This example adds several Node objects with images to a TreeView control. You can change the LineStyle and Style properties by selecting the alternate styles in two OptionButton control arrays. To try the example, place a TreeView control, an ImageList control, and two OptionButton control arrays (one with two buttons and one with eight) on a form, and paste the code into the form's Declarations section. Run the example, and click any OptionButton to change the LineStyle and Style properties.
Private Sub Form_Load()
' Add an image to the ImageList control.
Dim imgX As ListImage
Set imgX = ImageList1.ListImages. _
Add(,,LoadPicture("bitmaps\outline\leaf.bmp"))
TreeView1.ImageList = ImageList1 ' Initialize ImageList.
' Label OptionButton controls with line styles choices.
Option1(0).Caption = "TreeLines"
Option1(1).Caption = "RootLines"
' Select the first option, and set the LineStyle to TreeLines initially
Option1(0).Value = True
Treeview1.LineStyle = tvwTreeLines
' Label OptionButton controls with Style choices.
Option2(0).Caption = "Text only"
Option2(1).Caption = "Image & text"
Option2(2).Caption = "Plus/minus & text"
Option2(3).Caption = "Plus/minus, image & text"
Option2(4).Caption = "Lines & text"
Option2(5).Caption = "Lines, image & Text"
Option2(6).Caption = "Lines, plus/minus & Text"
Option2(7).Caption = "Lines, plus/minus, image & text"
' Select the last option, and set the initial Style
Option2(7).Value = True
Treeview1.Style = tvwTreelinesPlusMinusPictureText
Dim nodX As Node
Dim i as Integer
' Create root node.
Set nodX = TreeView1.Nodes.Add(,,,"Node " & "1",1)
For i = 1 to 5 ' Add 5 nodes.
Set nodX = TreeView1.Nodes. _
Add(i,tvwChild,,"Node " & CStr(i + 1),1)
Next I
nodX.EnsureVisible ' Show all nodes.
End Sub
Private Sub Option1_Click(Index as Integer)
' Change line style from OptionButton.
TreeView1.LineStyle = Index
End Sub
Private Sub Option2_Click(Index as Integer)
' Change Style with OptionButton.
TreeView1.Style = Index
Form1.Caption = "TreeView Style = " & Option2(Index).Caption
End Sub