Javatpoint Logo
Javatpoint Logo

VB.NET TreeView Control

The TreeView control is used to display a hierarchical representation of the same data in a tree structure. The top-level in the tree view is the root node with one or more child nodes. In addition, the root node can be contracted or expanded by clicking on the plus sign (+) button. It is also useful to provide the full path of the root node to the child node.

Let's create a TreeView control in the VB.NET Windows form using the following steps.

Step : We have to find the TreeView control from the toolbox and then drag and drop the TreeView control onto the window form, as shown below.

VB.NET TreeView Control

Step 2: Once the TreeView is added to the form, we can set various properties of the TreeView by clicking on the TreeView control.

Properties of the TreeView Control

There are following properties of the TreeView control.

Properties Description
Nodes The nodes property of the tree view control is used to gather all the nodes used in the tree.
SelectedNode It is used to obtain or set the tree node that is selected in the tree view control.
ShowRootLines It gets or sets a value that represents whether you want to draw lines between the tree nodes connected with the root of the tree view.
Path Separator The Path Separator property of the Tree View Control is used to set a delimiter string between the tree node paths.
ShowPlusMinus It is used to get or set a value representing whether you want to display the plus (+) or minus sign button next to tree nodes containing the child nodes.
ShowLines It takes a value representing whether you want to draw lines between the tree nodes of the tree view control.
TopNode It is used to get or set full visible tree nodes on top of other nodes in the tree view control.
VisibleCount It is used to obtain the fully visible tree node in the tree view control.
ItemHeight The ItemHeight property is used to set the height of each tree node in control.
Scrollable The Scrollable property is used in the tree-view to display the scroll bar by setting the value in control.

Methods of the TreeView Control

Method Description
GetNodeAt A GetNodeAt() method is used to get a node at the specified location of the tree view control.
Sort() A Sort method is used to sort the tree nodes that are available in the tree view control.
ExpandAll() As the name suggests, an ExpandAll method is used to expand all the tree nodes.
GetNodeCount It is used to count the number of nodes that are available in the tree view control.
CollapseAll It is used to collapse all tree nodes, including all child nodes in the tree view control.
ToString ToString method is used to return the name of the string that is in the tree view control.

Furthermore, we can also refer to VB.NET Microsoft documentation to get a complete list of TreeView control properties and methods.

Let's create a program to insert a node in the tree view control of the VB.NET form.

treeView.vb

Output:

VB.NET TreeView Control

Click on the Add New Node button to insert a new node into the tree view control. It displays the following image on the monitor.

VB.NET TreeView Control

Click on the OK button to insert the 'VB.NET' node in the tree view control.

VB.NET TreeView Control

Similarly, we can create all-new nodes in the TreeView control, as shown below.

VB.NET TreeView Control




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA