我如何允许在.NET的TreeView多选?多选、NET、TreeView

2023-09-02 11:58:25 作者:离人怎挽

我陷在.NET 2.0的Windows窗体。

I'm stuck in .NET 2.0 Windows Forms.

它看起来并不像选择多个节点的标准TreeView控件不存在的能力。

It doesn't look like the ability to select multiple nodes doesn't exist in the standard TreeView control.

我试图做到这一点的上下文菜单中选择。因此,检查盒子在这里不是一个可以接受的UI样式。

I'm trying to do this for context menu selection. So check boxes aren't an acceptable UI paradigm here.

什么是提供一个非常必要的功能最好的方法是什么?

What's the best way to provide that very necessary functionality?

推荐答案

我们在WTL项目一旦这样做,但所需要的基本工作是相同的.NET。为了实现多选树控件,您将需要画出树项目自己和覆盖键盘和鼠标操作。您还需要维护自己所选择的产品清单。

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.

不要忘记考虑选择规则(被家长和孩子允许,例如),不要忘记实现键盘快捷键,包括选择用Ctrl,Shift和Ctrl键+ Shift键,以及按空格键选择/取消。

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.