This example creates several Node objects. When you click on a Node object, the code first uses the Children property to determine if the Node has children nodes. If so, the caption of the form displays the text of the Child node.
Option Explicit
Private Sub Form_Load()
' This code creates a tree with 3 Node objects.
TreeView1.Style = tvwTreelinesPlusMinusText ' Style 6.
TreeView1.LineStyle = tvwRootLines 'Linestyle 1.
' Add several Node objects.
Dim nodX As Node ' Create variable.
Set nodX = TreeView1.Nodes.Add(, , "r", "Root")
Set nodX = TreeView1.Nodes.Add("r", tvwChild, "c1", "Child 1")
nodX.EnsureVisible ' Show all nodes.
Set nodX = TreeView1.Nodes.Add("c1", tvwChild, "c2", "Child 2")
Set nodX = TreeView1.Nodes.Add("c1", tvwChild, "c3", "Child 3")
nodX.EnsureVisible ' Show all nodes.
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As Node)
' If the Node does have children, then display the text of
' the child Node.
If Node.Children Then
Caption = Node.Child.Text
End If
End Sub