如何在树视图中选择子节点的父节点 [英] How to select the parent node of a child node in a treeview

查看:138
本文介绍了如何在树视图中选择子节点的父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个树视图,其中填充了根目录中的所有文件和目录。我需要以编程方式选择子节点的父目录。

我尝试了一些代码,但它只允许我选择根目录,这是树视图中的第一个目录,而不是父目录子节点的目录。

如果有人可以帮助我,我会非常感激。

谢谢。



我尝试过:



 list.SelectedNode = nodes [ 0 ]; 

解决方案

你甚至懒得阅读TreeNode上的文档,是吗? ?



每个TreeNode对象都有一个Parent,显然是指其父TreeNode。

 var parent = someChildNode.Parent; 


我这样解决了:

 list.SelectedNode = list。 TopNode; 


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:

list.SelectedNode = nodes[0];

解决方案

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;


I fixed it like this:

list.SelectedNode=list.TopNode;


这篇关于如何在树视图中选择子节点的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆