选择一个节点时折叠TreeView中的所有其他节点 [英] Collapse All Other Nodes in TreeView on Selection of One Node

查看:281
本文介绍了选择一个节点时折叠TreeView中的所有其他节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在 winform应用程序上有一个 treeview 控件.在这里,我要执行的操作是:折叠所有其他节点的级别,并仅消耗选定的节点.例如,假设场景:
-所有主题
+计算机科学
+数学

根节点是所有主题,两个子节点是1)计算机科学和2)数学.这两个子节点还有其他子节点.

当我选择计算机科学"时,应折叠数学"节点并应扩展计算机科学"节点.
如何实现呢?欢迎提出实现此目标的建议.

谢谢

Hi All,

I have a treeview control on winform application. Here, what I want to do is: Collapse all other nodes at his level and expend only selected node. For example, suppose the scenario:
- All Subject
+ Computer Science
+ Mathematics

Root Node is All Subjects and two child nodes are 1) Computer Science and 2) Mathematics. These two child nodes have further child nodes.

When I select Computer Science, teh Mathematic node should be collapsed and Computer Science Node should be expanded.
How can this be achieved ? Suggestion to accomplish this are welcomed.

Thanks

推荐答案

建议完成此操作.
只需循环遍历父节点,然后折叠所有父节点,留下当前节点即可!



更好的是,折叠全部,然后仅扩展当前选择.

以下内容将帮助您:
MSDN:TreeView.CollapseAll方法 [ ^ ]
MSDN:TreeNode.Collapse方法 [ ^ ]
MSDN:TreeNode.Expand方法 [ ^ ]
Suggestion to accomplish this are welcomed.
Just loop though the parent nodes and collapse all leaving the current one!

OR

even better, collapse all and then just expand the current selection.

Following will help:
MSDN: TreeView.CollapseAll Method[^]
MSDN: TreeNode.Collapse Method[^]
MSDN: TreeNode.Expand Method[^]


这篇关于选择一个节点时折叠TreeView中的所有其他节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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