Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i have a tables in my database
1)admin
2)users
3)roles

i want to display it in tree view in my form dynamically plz help me
Posted

1 solution

Initialize the TreeView on the form. You can do this easily by dragging/dropping the treeview control from the control-bar in Visual Studio. Usually it is named as treeView1 when you do it by dragging/dropping. After that get the list of tables you want to display in the treeview; better pull that list from the database. When you have the list, you can use the following code to assign nodes to the treeview: (Assuming that you have list of table names in a List)

foreach(string tableName in tablesNameList) //tablesNameList is the list containing all the names of the tables
{
TreeNode treeNode = new TreeNode(tableName);

// if you want to add icon against each node or you want to assign some other properties you can do it here.
//After that you need to add that node to the treeview control. you can do it as below
treeView1.Nodes.Add(treeNode); // this line will add the node to the treeview control.

}

Hope I have answered your question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900