Home > DeveloperSection > Articles > TreeView Control in C#.Net

TreeView Control in C#.Net


C# C# 
Ratings:
4 Comment(s)
 9352  View(s)
Rate this:

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

Code:

private void frmTreeView_Load(object sender, EventArgs e)

{

            treeView1.Nodes.Add("");

            treeView1.Nodes[0].Text = "Database";// this is parent 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

 

When you expand the Database node then child node of database will show .TreeView Control in C#.Net

 

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

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


How to receive record through database in treeview

By Manmohan Jha on   3 years ago
Receive record parent wise...
Ex...
Parent
....child
......subchild
..........subchild
..............subchild
parent2....child
......subchild
..........subchild
..............subchild

how do that?

Thx & regard
Manmohan Jha
manmohan_jh@sify.com


Not helpful

By Manmohan Jha on   3 years ago
how to receive record dynamicaly to database...

Thx & regard
Manmohan Jha

TreeView

By Chris S on   3 years ago

Could you please elaborate your problem?


Don't want to miss updates? Please click the below button!

Follow MindStick