Share via


Visual Basic: Windows Controls

NodeClick Event Example

This example adds several Node objects to a TreeView control. When a Node is clicked, the NodeClick event is triggered and is used to get the Node object's index and text. 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 any Node.

  Private Sub Form_Load()
   Dim nodX As Node
   Set nodX = TreeView1.Nodes.Add(,,"R","Root")
   nodX.Expanded = True
   Set nodX = TreeView1.Nodes.Add(,,"P","Parent")
   nodX.Expanded = True
   Set nodX = TreeView1.Nodes.Add("R",tvwChild,,"Child 1")
   Set nodX = TreeView1.Nodes.Add("R",tvwChild,,"Child 2")
   Set nodX = TreeView1.Nodes.Add("R",tvwChild,,"Child 3")
   Set nodX = TreeView1.Nodes.Add("P",tvwChild,,"Child 4")
   Set nodX = TreeView1.Nodes.Add("P",tvwChild,,"Child 5")
   Set nodX = TreeView1.Nodes.Add("P",tvwChild,,"Child 6")
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As Node)
   Form1.Caption = "Index = " & Node.Index & " Text:" & Node.Text
End Sub