Hi all
the treeview i am creating here works very well but i tried so many ways to add tag to the child nodes but i could not... can any one tell me how to add tag to the nodes... that are created from the database...
I could add tag to rootNode but cannot add to child nodes...
public void FillTree()
{
SqlCeConnection Connect = new SqlCeConnection("Data Source = data.sdf");
Connect.Open();
DataTable dtTree = new DataTable();
string sql = "SELECT * FROM Assembly";
SqlCeDataAdapter Adapt = new SqlCeDataAdapter(sql, Connect);
Adapt.Fill(dtTree);
Adapt.Dispose();
treeView1.BeginUpdate();
treeView1.Nodes.Clear();
TreeNode rootNode = treeView1.Nodes.Add("Root");
rootNode.Tag = "RootDB";
CreateTreeView(rootNode.Nodes, 0, dtTree);
rootNode.Nodes[0].Expand();
treeView1.Select();
treeView1.EndUpdate();
Connect.Close();
}
// create tree
public void CreateTreeView(TreeNodeCollection parentNode, int parentID, DataTable mytab)
{
foreach (DataRow dta in mytab.Rows)
{
if (Convert.ToInt32(dta["ParentId"]) == parentID)
{
String key = dta["Id"].ToString();
String text = dta["Name"].ToString();
TreeNodeCollection newParentNode = parentNode.Add(key, text).Nodes;
CreateTreeView(newParentNode, Convert.ToInt32(dta["Id"]), mytab);
}
}
}
Thanks
vince