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.
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.
||The nodes property of the tree view control is used to gather all the nodes used in the tree.
||It is used to obtain or set the tree node that is selected in the tree view control.
||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.
||The Path Separator property of the Tree View Control is used to set a delimiter string between the tree node paths.
||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.
||It takes a value representing whether you want to draw lines between the tree nodes of the tree view control.
||It is used to get or set full visible tree nodes on top of other nodes in the tree view control.
||It is used to obtain the fully visible tree node in the tree view control.
||The ItemHeight property is used to set the height of each tree node in control.
||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
||A GetNodeAt() method is used to get a node at the specified location of the tree view control.
||A Sort method is used to sort the tree nodes that are available in the tree view control.
||As the name suggests, an ExpandAll method is used to expand all the tree nodes.
||It is used to count the number of nodes that are available in the tree view control.
||It is used to collapse all tree nodes, including all child nodes in the tree view control.
||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.
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.
Click on the OK button to insert the 'VB.NET' node in the tree view control.
Similarly, we can create all-new nodes in the TreeView control, as shown below.