允许在 .NET TreeView 中进行多选
我陷入了 .NET 2.0 Windows 窗体的困境。
标准 TreeView
控件中似乎不具备选择多个节点的功能。
我正在尝试为上下文菜单选择执行此操作。 因此,复选框在这里不是可接受的 UI 范例。
提供非常必要的功能的最佳方式是什么?
I'm stuck in .NET 2.0 Windows Forms.
It doesn't look like the ability to select multiple nodes exists in the standard TreeView
control.
I'm trying to do this for a context menu selection. So check boxes aren't an acceptable UI paradigm here.
What's the best way to provide that very necessary functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我们在 WTL 项目中做过一次,但所需的基本工作对于 .NET 来说是相同的。 要实现多选树控件,您需要自己绘制树项目并覆盖键盘和鼠标处理。 您还需要维护自己的所选项目列表。
不要忘记考虑选择规则(例如,是否允许父母和孩子),并且不要忘记实现键盘快捷键,包括使用 Ctrl、Shift 和 Ctrl+Shift 进行选择,以及用于选择/取消选择的空格键。
We did this in a WTL project once, but the basic work needed is the same for .NET. To achieve a multiple selection tree control, you will need to draw the tree items yourself and override the keyboard and mouse handling. You will also need to maintain your own list of items that are selected.
Don't forget to consider selection rules (are parents and children allowed, for example), and don't forget to implement the keyboard shortcuts including selection using Ctrl, Shift, and Ctrl+Shift, as well as the Spacebar for selecting/deselecting.
TreeView.CheckBoxes
TreeView.CheckBoxes
复选框是一个选项吗? 或者您想要像在列表框中那样进行选择吗?
CodeProject 上有一个多选树控件:多选树视图
Are check-boxes an option? or do you want the select like you get in a list box?
There is a multi-select tree control available on CodeProject:Multi-Select Tree View
最简单的解决方案是扩展框架附带的现有 TreeView 控件,并使用捕获多个选择的逻辑重写 OnBeforeSelect 和 OnAfterSelect 方法。
可以在此处找到示例: http://www.arstdesign.com/articles/treeviewms.html< /a>
The simplest solution would be to extend the existing TreeView control shipped with the framework and override the OnBeforeSelect and OnAfterSelect methods with logic to capture multiple selections.
An example can be found here: http://www.arstdesign.com/articles/treeviewms.html
下面的代码将允许您调整使用的背景颜色,以确保所有选定的节点都突出显示。
The below code will allow you to adjust the background colour you use, to ensure that all selected nodes are highlighted.
您可能会考虑第三方解决方案。 Infragistics 树可以做到这一点。 不是免费的,但是花在寻找解决方案上的时间也不是真正免费的。
You might look at a 3rd party solution. The Infragistics tree does this. Not free, but the time spent trying to find a solution isn't really free, either.