Click here to Skip to main content
15,908,901 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I need my key nodes tree, but I can't find them.
I use this source code, but its result is a empty msgbox, that have just an ok button.
Please help me:
C#
private TreeNode Create_Tree(string Key, string Name)
{
      TreeNode tr = new TreeNode(Name);

      for (int i = 0; i < dataGridViewSub.Rows.Count; i++)
      {
           try
           {
               if (
                     (dataGridViewSub.Rows[i].Cells[2].Value.ToString() == Key)
                        &&
                        (dataGridViewSub.Rows[i].Cells[1].Value.ToString() != "1000")
                     )
                  {
                        tr.Nodes.Add(
                            Create_Tree(dataGridViewSub.Rows[i].Cells[1].Value.ToString(),
                                dataGridViewSub.Rows[i].Cells[5].Value.ToString()));
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return tr;
        }


Calling my function:
C#
treeView1.Nodes.Clear();

if (dataGridViewSub.Rows.Count > 0)
      treeView1.Nodes.Add(Create_Tree(dataGridViewSub.Rows[0].Cells[1].Value.ToString(), dataGridViewSub.Rows[0].Cells[5].Value.ToString()));


And showing key:
C#
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
      MessageBox.Show(treeView1.SelectedNode.Name);
}


Thanks
Posted
v2

1 solution

Try
C#
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
      MessageBox.Show(e.SelectedNode.Name);
}
 
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