---
title: "TreeView Control in C#.Net"  
description: "The TreeView control is  used to display a hierarchy of nodes. You can expand and collapse these nodes  by clicking them.Drag and drop TreeView contro"  
author: "Anonymous User"  
published: 2011-01-24  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/411/treeview-control-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# TreeView Control in C#.Net

The TreeView control is used to display a hierarchy of nodes. You can expand and

collapse these nodes by clicking them.Drag and drop TreeView control from

toolbox on the window Form.\

![TreeView Control in C#.Net](https://www.mindstick.com/mindstickarticle/92725a20-3aff-4998-b68b-5bcadb4d8b23/images/9a4d5eb7-d9e0-4f31-aae8-9e891b3f2f0d.png)

##### Code:

```
private void frmTreeView_Load(object sender, EventArgs e){            treeView1.Nodes.Add("");            treeView1.Nodes[0].Text= "Database";// this isparent node            // fallowing are the child node of 'Database'            treeView1.Nodes[0].Nodes.Add("sql server");         
  treeView1.Nodes[0].Nodes.Add("my sql");            treeView1.Nodes.Add("");            treeView1.Nodes[1].Text
= "Programming Language";// this is parent node            // fallowing are the child node of 'Programming Language'            treeView1.Nodes[1].Nodes.Add("C#");            treeView1.Nodes[1].Nodes.Add("J#");            treeView1.Nodes[1].Nodes.Add("java");}
```

##### Run the project

![TreeView Control in C#.Net](https://www.mindstick.com/mindstickarticle/92725a20-3aff-4998-b68b-5bcadb4d8b23/images/d2a9d4ac-7424-4add-82ff-1938c5becc09.png)

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

![TreeView Control in C#.Net](https://www.mindstick.com/mindstickarticle/92725a20-3aff-4998-b68b-5bcadb4d8b23/images/44de708c-3d77-4dfd-89d1-2a2aab0f492a.png)\

TreeView Properties

\

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

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

##### Example:

```
private void frmTreeView_Load(object sender, EventArgs e){            //change forecolor of treeview            treeView1.ForeColor= Color.Red;}
```

\

![TreeView Control in C#.Net](https://www.mindstick.com/mindstickarticle/92725a20-3aff-4998-b68b-5bcadb4d8b23/images/654b1193-f910-4031-9b62-27d109da820d.png)

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

##### Example:

```
private void frmTreeView_Load(object sender, EventArgs e){            //Change BackColor of TreeView             treeView1.BackColor = Color.CadetBlue;}
```

\

![TreeView Control in C#.Net](https://www.mindstick.com/mindstickarticle/92725a20-3aff-4998-b68b-5bcadb4d8b23/images/d7070dc1-ac1e-4031-ab7f-ff2e81ef9a13.png)

\

---

Original Source: https://www.mindstick.com/articles/411/treeview-control-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
