TreeView Control in VB.Net

The TreeView control is used to display a hierarchy of nodes. You can expand and collapse these nodes by clicking them.

How to use TreeView control

Drag and drop TreeView from toolbox on the window Form

TreeView Control in VB.Net

Code:

Public Class mindstick

 

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

      'adding data in TreeView

        TreeView1.Nodes.Add("Database") 'this is root node

        TreeView1.Nodes(0).Nodes.Add("sql server")

        TreeView1.Nodes(0).Nodes.Add("my sql")

        TreeView1.Nodes(0).Nodes.Add("Oracle")

        TreeView1.Nodes.Add("Programming langauage")'this is root node

        TreeView1.Nodes(1).Nodes.Add("C#")

        TreeView1.Nodes(1).Nodes.Add("VB")

        TreeView1.Nodes(1).Nodes.Add("Java")

 

    End Sub

End Class

 

Run the project

TreeView Control in VB.Net

When you expand the Database node then child node of database will show.

TreeView Control in VB.Net

TreeView Properties

ShowRootLine: set the ShowRootLine to show or hide Line , By default it is set true.

ForeColor:  ForeColor of TreeView can be changed through TreeView ForeColor property.

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

        'change TreeView ForeColor

        TreeView1.ForeColor = Color.Red

End Sub

TreeView Control in VB.Net

BackColor: BackColor of TreeView can be changed through TreeView BackColor property.

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

        'change TreeView BckColor

        TreeView1.BackColor = Color.PowderBlue

 End Sub

TreeView Control in VB.Net

  Modified On Nov-24-2017 06:28:47 AM

Leave Comment