Click here to Skip to main content
15,917,456 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir
I want to Add nodes in Treeview Dynamically. Also I want to link those nodes with database. so that when i click that node, it should display data whether its text, html,image,etc.

Regards
Mehsud
Posted

//This Sample is one way to bind data to a treenode.

class dataCls
{
public int Key { get; set; }
public object Data { get; set; }
}

class Sample
{
private void createTreeStructure()
{
// Your sql query using SqlDataAdapter or SqlDataReader.
// this example will use SqlDataReader

SqlConnection conn = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(
"select cID, cName, cData from tblExample",
conn);

SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read());
{
dataCls dataObj= new dataCls();
dataObj.Key = (int)dr[0];
dataObj.Data = dr[2];
TreeNone n = new TreeNode((string)dr[1]);
n.Tag = dataObj;
treeView1.Nodes.Add(n);
}
}
}
 
Share this answer
 
You can see this links

Click

Click

Click
 
Share this answer
 
Comments
Mehsud 30-Oct-10 3:20am    
Excellent Links Shakil Sir

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