CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    7

    C# Treeview nodes help

    Hi Guys

    Lets say I have a treeview with parent nodes that have child nodes that have grandchild nodes.

    The Question I have is lets say I select a grand child node. . . .How will I detect what that grand child nodes value is and the child and parent value is of the selected grandchild?


    Thanks?

  2. #2
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: C# Treeview nodes help

    Map the NodeClick event of the treeview, when clicked... check the node.text values using Parent and Nodes properties as required to get values up and down the family tree relative to that node...

    Code:
            private void onNodeClick(object sender, TreeNodeMouseClickEventArgs e)
            {
                string selectedValue = e.Node.Text;  // selected (clicked) node
                string childOfSelectedValue = e.Node.Nodes[0].Text;   // 1st child of selected
                string parentOfSelectedValue = e.Node.Parent.Text;   // parent of selected
            }
    If you wanted the grand parent...
    Code:
    e.Node.Parent.Parent.Text;
    etc....

  3. #3
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: C# Treeview nodes help

    Note: You'll want to do some checking of course, to make sure child nodes and parent nodes exist and have values before trying to access them...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured