Hi guys, i am having a problem regarding a tree view control. I am very new to C# and stuck on how to add ID to the corresponding tree nodes. I am not sure whether this lines of code holds ID or if not then what should i include. I want to get the ID of
the selected node. How do i proceed please let me know. My code is given below -
Thanks in advance.
Thanks in advance.
private void PopulateTreeView() { treeDepartments.Nodes.Clear(); String strConn = "Server =server;Database =DB;Integrated Security = True;"; SqlConnection conn = new SqlConnection(strConn); SqlDataAdapter da = new SqlDataAdapter("Select * from tSubDepartments", conn); SqlDataAdapter daCategories = new SqlDataAdapter("Select * from tDepartments", conn); da.Fill(ds, "tSubDepartments"); daCategories.Fill(ds, "tDepartments"); ds.Relations.Add("Dept_SubDept", ds.Tables["tDepartments"].Columns["dpCode"], ds.Tables["tSubDepartments"].Columns["dpCode"]); foreach (DataRow dr in ds.Tables["tDepartments"].Rows) { int id = Convert.ToInt32(dr["dpCode"]); TreeNode tn = new TreeNode(dr["dpName"].ToString()); foreach (DataRow drChild in dr.GetChildRows("Dept_SubDept")) { tn.Nodes.Add(drChild["sdName"].ToString()); } treeDepartments.Nodes.Add(tn); } }
Apurba