Expand Event Example

This example adds several Node objects to a TreeView control. When a Node is expanded, the Expand event is generated, and information about the Node is displayed. 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 expand the nodes.

Private Sub Form_Load()
   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(, , "RP", "Root Parent")
   Set nodX = TreeView1.Nodes.Add("RP", tvwChild, "C1", "Child1")
   Set nodX = TreeView1.Nodes.Add("C1", tvwChild, "C2", "Child2")
   Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C3", " Child3")
   Set nodX = TreeView1.Nodes.Add("C2", tvwChild, "C4", " Child4")
   TreeView1.Style = tvwTreelinesPlusMinusText   ' Style 6.
   TreeView1.LineStyle = tvwRootLines   ' Style 1
End Sub

Private Sub TreeView1_Expand(ByVal Node As Node)
   Select Case Node.Key Like "C*"
   Case Is = True
      MsgBox Node.Text & " is a child node."
   End Select
End Sub