Adds a Node object to a Treeview control's Nodes collection.
Syntax
object.Add(relative, relationship, key, text, image, selectedimage)
The Add method syntax has these parts:
Part | Description |
object | Required. An object expression that evaluates to an object in the Applies To list. |
relative | Optional. The index number or key of a pre-existing Node object. The relationship between the new node and this pre-existing node is found in the next argument, relationship. |
relationship | Optional. Specifies the relative placement of the Node object, as described in Settings. |
key | Optional. A unique string that can be used to retrieve the Node with the Item method. |
text | Required. The string that appears in the Node. |
image | Optional. The index of an image in an associated ImageList control. |
selectedimage | Optional. The index of an image in an associated ImageList control that is shown when the Node is selected. |
Settings
The settings for relationship are:
Constant | Value | Description |
tvwFirst | 0 | First. The Node is placed before all other nodes at the same level of the node named in relative. |
tvwLast | 1 | Last. The Node is placed after all other nodes at the same level of the node named in relative. Any Node added subsequently may be placed after one added as Last. |
tvwNext | 2 | (Default) Next. The Node is placed after the node named in relative. |
tvwPrevious | 3 | Previous. The Node is placed before the node named in relative. |
tvwChild | 4 | Child. The Node becomes a child node of the node named in relative. |
Note If no Node object is named in relative, the new node is placed in the last position of the top node hierarchy.
Remarks
The Nodes collection is a 1-based collection.
As a Node object is added it is assigned an index number, which is stored in the Node object's Index property. This value of the newest member is the value of the Node collection's Count property.
Because the Add method returns a reference to the newly created Node object, it is most convenient to set properties of the new Node using this reference. The following example adds several Node objects with identical properties:
Dim nodX As Node ' Declare the object variable.
Dim I as Integer ' Declare a counter variable.
For I = 1 to 4
Set nodX = TreeView1.Nodes.Add(,,,"Node " & Cstr(i))
' Use the reference to set other properties, such as Enabled.
nodX.Enabled = True
' Set image property to image 3 in an associated ImageList.
nodX.ExpandedImage = 3
Next I