Treeview Control

TreeView control is used to display hierarchical tree like information such as a directory hierarchy. The top level in a tree view are root nodes that can be expanded or collapsed if the nodes have child nodes.

vb.net-treeview.jpg

The user can expand the TreeNode by clicking the plus sign (+) button, if one is displayed next to the TreeNode, or you can expand the TreeNode by calling the TreeNode.Expand method. When a parent node is expanded, its child nodes are visible. You can also navigate through tree views with various properties: FirstNode, LastNode, NextNode, PrevNode, NextVisibleNode, PrevVisibleNode.

The fullpath method of treeview control provides the path from root node to the selected node.

TreeView1.SelectedNode.FullPath

Tree nodes can optionally display check boxes. To display the check boxes, set the CheckBoxes property of the TreeView to true.

TreeView1.CheckBoxes = True

The following Vb.Net program shows a simple demonstration of treeview control




Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Dim tNode As TreeNode
		tNode = TreeView1.Nodes.Add("Websites")

		TreeView1.Nodes(0).Nodes.Add("Net-informations.com")
		TreeView1.Nodes(0).Nodes(0).Nodes.Add("CLR")

		TreeView1.Nodes(0).Nodes.Add("Vb.net-informations.com")
		TreeView1.Nodes(0).Nodes(1).Nodes.Add("String Tutorial")
		TreeView1.Nodes(0).Nodes(1).Nodes.Add("Excel Tutorial")

		TreeView1.Nodes(0).Nodes.Add("Csharp.net-informations.com")
		TreeView1.Nodes(0).Nodes(2).Nodes.Add("ADO.NET")
		TreeView1.Nodes(0).Nodes(2).Nodes(0).Nodes.Add("Dataset")

	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		MsgBox(TreeView1.SelectedNode.FullPath)

	End Sub
End Class

 VB.Net GUI - Related Contents



.