Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have a treeview that gets populated with all the files and directories in the root directory. I need to select the parent directory of a child node programatically.
I have tried some code, but it only allows me to select the root directory, which is the first directory in the treeview and not the parent directory of the child node.
If someone could please help me, I would really appreciate it.
Thanks.

What I have tried:

C#
list.SelectedNode = nodes[0];
Posted
Updated 17-Mar-17 8:02am

You didn't even bother reading the documentation on TreeNode, did you?

Every TreeNode object has a Parent that, obviously, refers to its parent TreeNode.
var parent = someChildNode.Parent;
 
Share this answer
 
I fixed it like this:
C#
list.SelectedNode=list.TopNode;
 
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