Link to home
Start Free TrialLog in
Avatar of MichelleLacy
MichelleLacy

asked on

Treeview node ID

I have a treeview with two levels.  The user clicks a check box that selects the name in the last node.  I move the text from this node into a text box.  Well, I also want to capture the id and put it into an array.  How do I do this?
foreach (DataRow dr in tissueLevel.Rows)
                    {
                        if (!treeView1.Nodes.ContainsKey(dr["tg_id"].ToString()))
                        {
                            treeView1.Nodes.Add(dr["tg_id"].ToString(), dr["name"].ToString());
                        }
                    }
                    foreach (DataRow dr in tissueLevel.Rows)
                    {
                        TreeNode[] nodes = treeView1.Nodes.Find(dr["tg_id"].ToString(), true);
                        if (nodes.Length > 0)
                        {
                            TreeNode node = nodes[0];
                            if (!node.Nodes.ContainsKey(dr["auto_id"].ToString()))
                            {
                                node.Nodes.Add(dr["auto_id"].ToString(), dr["label"].ToString());
                            }
                        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Priest04
Priest04
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MichelleLacy
MichelleLacy

ASKER

that is very logical and so obvious that I did not see it.  It helps to have another set of eyes.  Thanks so much!!!
You are welcome.

Goran
I figured out how to do it.  I tricky part was the diffference between the node text and the node name.  The text is what is displayed in the textbox, but the node name is the id that was after.  So to add to a list, it is simply  myList.Add(n2.Name.ToString())