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.

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

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

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;
}

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;
}

|