如何控制 .Net Forms.TreeView 中的复选框?

发布于 2024-07-04 19:47:11 字数 188 浏览 10 评论 0 原文

我有一个 .Net 桌面应用程序,其中 TreeView 作为 UI 元素之一。

我希望能够多重选择该 TreeView,但根本不支持这一点。

所以我在树中添加了复选框,我的问题是只有一些项目是可选的,而那些不能选择的项目则不能一致地级联选择。

有什么方法可以在显示其他复选框时禁用或隐藏某些复选框吗?

I have a .Net desktop application with a TreeView as one of the UI elements.

I want to be able to multi-select that TreeView, only that isn't supported at all.

So I'm adding check-boxes to the tree, My problem is that only some items are selectable, and those that aren't can't consistently cascade selections.

Is there any way to disable or hide some check-boxes while displaying others?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里梦着梦中梦 2024-07-11 19:47:11

我最近写的一个编辑器也遇到了非常类似的问题。 最后,我使用了TreeNodeBackColor属性来确定节点的选择状态。 然后,我为 SelectionChanged 事件编写了一个处理程序,该处理程序检查 Shift/Control 键的状态,以确定所选节点是否被添加到选择中/从选择中删除或创建新选择。 还有当前选择的节点的 Generic::List 以消除任何树搜索。

I had a very similar problem in an editor I wrote recently. In the end, I used the TreeNode's BackColor property to determine the selection state of the node. I then wrote a handler for the SelectionChanged event that checked the state of the Shift/Control keys to determine if the selected node was being added to/removed from the selection or creating a new selection. There was also a Generic::List<> of the nodes that were currently selected to eliminate any tree searches.

小帐篷 2024-07-11 19:47:11

TreeView 的默认行为是,当 Checkboxes 属性设置为 true,则将为所有 TreeNode 显示复选框。

您正在寻找的行为 - 禁用或隐藏某些复选框 - 是正常行为的自定义修改。 您可以创建覆盖默认行为的 TreeView 或 TreeNode 的自定义实现。 另一件可以尝试的事情是使用 TreeView。StateImageList 属性。 要了解更多信息,请查看一些网站:

The default behavior of TreeView is that when the Checkboxes property is set to true, that checkboxes will be shown for all TreeNodes.

The behavior that you are looking for - to disable or hide some checkboxes - is a custom modification of the normal behavior. You can create a custom implementation of TreeView or TreeNode that overrides the default behavior. One other thing to try would be to use the TreeView.StateImageList property. Some sites to check out for more info:

你的他你的她 2024-07-11 19:47:11

MultiSelectTreeView

为什么 .NET 没有多选树视图? 一个有很多用途,在树视图中打开复选框是一个非常糟糕的选择。

MultiSelectTreeView:

Why doesn't .NET have a multiselect treeview? There are so many uses for one and turning on checkboxes in the treeview is a pretty lousy alternative.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文