- This topic helps to learn the working of TreeView control used in VB programming.
- Tools needed: TreeView1 (TreeView1), Button1 (Button1).
- User can expand the Tree node through clicking the plus sign (+) button. When a parent node expanded, its child node become visible.
TreeView Control
- The Windows Forms TreeView control displays a hierarchy of nodes, like the way files and folders are displayed in the left pane of the Windows Explorer feature in Windows operating systems.
- The top level of the TreeView is called Root node that can be expanded or collapsed if they have a child node
TreeView.Nodes Property – TreeView Control in VB
- It helps to get the collection of tree nodes that are assigned to the tree view control.
- Syntax for TreeView.Nodes Property
|
1 2 |
'Declaration Public ReadOnly Property Nodes As TreeNodeCollection |
TreeView.SelectedNode Property – TreeView Control in VB
- It helps to get or set the tree node that is currently selected in the tree view control.
- Syntax
|
1 2 3 |
'Declaration <BrowsableAttribute(False)> _ Public Property SelectedNode As TreeNode |
TreeView.SelectedNode.FullPath Property – TreeView Control in VB
- The fullpath method of treeview control provides the path from root node to the selected node.
- Syntax
|
1 |
TreeView1.SelectedNode.FullPath |
TreeView.ShowPlusMinus Property – TreeView Control in VB
- It helps to change the values indicating whether plus-sign (+) and minus-sign (-) buttons are displayed next to tree nodes that contain child tree nodes.
- Syntax
|
1 2 |
'Declaration Public Property ShowPlusMinus As Boolean |
TreeView.ShowRootLines Property – TreeView Control in VB
- It helps to get or set the values indicating whether lines are drawn between the tree nodes that are at the root of the tree view
- Syntax
|
1 2 |
'Declaration Public Property ShowRootLines As Boolean |
TreeView Control in VB – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.Nodes.Add("Class Room") TreeView1.Nodes(0).Nodes.Add("STD I") TreeView1.Nodes(0).Nodes(0).Nodes.Add("DIV A") TreeView1.Nodes(0).Nodes.Add("STD II") TreeView1.Nodes(0).Nodes(1).Nodes.Add("DIV B") TreeView1.Nodes(0).Nodes.Add("STD III") TreeView1.Nodes(0).Nodes(2).Nodes.Add("DIV C") 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 |

TreeView Control in VB
TreeView Control in VB




