Add Method Example (Nodes Collection)

The following example adds two Node objects to a TreeView control. To try the example, place a TreeView control on a form, and paste the code into the form's Declarations section. Run the example, and click the Node object to expand it.

Private Sub Form_Load()
   ' Set Treeview control properties.
   TreeView1.LineStyle = tvwRootLines  ' Linestyle 1

   ' Add Node objects.
   Dim nodX As Node  ' Declare Node variable.
   ' First node with 'Root' as text.
   Set nodX = TreeView1.Nodes.Add(, , "r", "Root")

   ' This next node is a child of Node 1 ("Root").
   Set nodX = TreeView1.Nodes.Add("r", tvwChild, "child1", "Child")

End Sub