PathSeparator Property Example

This example adds several Node objects to a TreeView control, and uses an OptionButton control array to change the PathSeparator property. To try the example, place a TreeView control and an OptionButton control array on a form, and paste the code into the form's Declarations section. Run the example, select a Node, and click the form. Change the PathSeparator property value using the OptionButtons.

Private Sub Form_Load
   TreeView1.BorderStyle = vbFixedSingle ' Show border.
   ' Label OptionButton controls with Style choices.
   Option1(0).Caption = "/"
   Option1(1).Caption = "-"
   Option1(2).Caption = ":"

   ' Select the last option, and set the initial Style
   Option2(1).Value = True
   Treeview1.PathSeparator = Option1(1).Caption

   Dim nodX As Node
   Dim i As Integer
   Set nodX = TreeView1.Nodes.Add(,,,CStr(1))    ' Add first node.

   For i = 1 to 5   ' Add other nodes.
      Set nodX = TreeView1.Nodes.Add(i,tvwChild,,CStr(i + 1))
   Next i

   nodX.EnsureVisible   ' Ensure all are visible.
End Sub

Private Sub Option1_Click(Index as Integer)
   ' Change the delimiter character.
   TreeView1.PathSeparator = Option1(Index).Caption
End Sub

Private Sub TreeView1_NodeClick(ByVal Node As Node)
   ' Show path in form's caption.
   Me.Caption = Node.FullPath
End Sub