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

 

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


  1. 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

  1. how to receive record dynamicaly to database...


    Thx & regard
    Manmohan Jha

  1. Could you please elaborate your problem?

Leave Comment