---
title: "TreeView Control in VB.Net"  
description: "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"  
author: "Pushpendra Singh"  
published: 2010-12-12  
updated: 2020-05-02  
canonical: https://www.mindstick.com/articles/325/treeview-control-in-vb-dot-net  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# TreeView Control in VB.Net

The [TreeView control](https://www.mindstick.com/articles/411/treeview-control-in-c-sharp-dot-net) is used to display a hierarchy of [nodes](https://www.mindstick.com/news/2242/on-thursday-google-cloud-announced-the-debut-of-its-own-node-hosting-service-for-web3-developers). You can [expand](https://www.mindstick.com/articles/13054/here-s-how-crm-can-help-you-expand-your-business) and collapse these nodes by clicking them.\

#### How to use TreeView control

[Drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) TreeView from [toolbox on the window Form](https://www.mindstick.com/Articles/621/gridview-inside-gridview-in-asp-dot-net-nested-gridview)

![TreeView Control in VB.Net](https://www.mindstick.com/mindstickarticle/e77f2085-dabb-4510-a98b-0c59a752016e/images/7855764d-e8e2-4cd2-9eda-f9c6cc9ae475.png)

#### 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 SubEnd Class 
```

#### Run the project

![TreeView Control in VB.Net](https://www.mindstick.com/mindstickarticle/e77f2085-dabb-4510-a98b-0c59a752016e/images/1dde4daf-dde4-48ee-9ef3-93de1aed31e1.png)

When you expand the [Database](https://www.mindstick.com/articles/71/how-to-create-xml-file-of-database-in-c-sharp) [node](https://www.mindstick.com/forum/161418/what-is-node-js-and-how-does-it-work) then the child node of the database will show.

![TreeView Control in VB.Net](https://www.mindstick.com/mindstickarticle/e77f2085-dabb-4510-a98b-0c59a752016e/images/6a51ce80-6b36-49d3-b3cd-f3113367cdfc.png)

### TreeView Properties

**ShowRootLine:** set the ShowRootLine to show or hide Line, By [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources), it is set to 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.RedEnd Sub
```

![TreeView Control in VB.Net](https://www.mindstick.com/mindstickarticle/e77f2085-dabb-4510-a98b-0c59a752016e/images/609cbf02-680a-4b2a-83d5-10870f5862b5.png)

**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](https://www.mindstick.com/mindstickarticle/e77f2085-dabb-4510-a98b-0c59a752016e/images/b80c0665-45fc-4b9f-bf07-4e419d77ca26.png)

---

Original Source: https://www.mindstick.com/articles/325/treeview-control-in-vb-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
