|
-
June 13th, 2011, 01:42 AM
#1
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?
-
June 13th, 2011, 12:18 PM
#2
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....
-
June 13th, 2011, 12:19 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|