Visual Basic: Windows Controls

Indentation Property Example

This example adds several Node objects to a TreeView control, while the Indentation property is shown in the form's caption. An OptionButton control array provides alternate values for the Indentation width. To try the example, place a TreeView control and a control array of three OptionButton controls on a form, and paste the code into the form's Declarations section. Run the example, and click an OptionButton to change the Indentation property.

  Private Sub Form_Load()
   ' Label OptionButton controls with Indentation choices.
   Option1(0).Caption = "250"
   Option1(1).Caption = "500"
   Option1(2).Caption = "1000"

   ' Select the first option, and set the indentation to 250 initially
   Option1(0).Value = True
   Treeview1.Indentation = 250

   Dim nodX As Node
   Dim i As Integer

   Set nodX = TreeView1.Nodes.Add(,,,CStr(1)) ' Add first node.

   For i = 1 To 6   ' Add 6 nodes.
      Set nodX = TreeView1.Nodes.Add(i,tvwChild,,CStr(i + 1))
   Next i

   nodX.EnsureVisible   ' Makes sure all nodes are visible.
   Form1.Caption = "Indentation = " & TreeView1.Indentation
End Sub

Private Sub Option1_Click(Index as Integer)   ' Change Indentation with OptionButton value.
   TreeView1.Indentation = Val(Option1(Index).Caption)
   Form1.Caption = "Indentation = " & TreeView1.Indentation
End Sub