仅在子节点中选中复选框? [英] Checkboxes only in Children Nodes?

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

问题描述

我有许多按类别分组的项目(节点),我想在 TreeView 中显示它们,其中父级是文本,子级是 CheckBoxes

I have many items (Nodes) grouped by category and I want to display them in a TreeView where parent are text and children are CheckBoxes :

+-CategoryA(Text)
---.A1(CheckBox)
---.A2(CheckBox)
+-CategoryB(Text)
---.B1
---.B2
---.B3
+-CategoryC(Text)
---.C1(CheckBox)
---.C2(CheckBox)

这是一个代码示例:

TreeNode testNodeA = new TreeNode("A"); 
TreeNode testNodeB = new TreeNode("B");
TreeNode testNodeC = new TreeNode("C");
TreeNode[] array = new TreeNode[] { testNodeA, testNodeB, testNodeC };
TreeNode cat = new TreeNode("Categorie X", array);
myTreeView.Nodes.Add(cat);

我已经找到了类似的问题此处,但是该解决方案并不优雅,因为它使用 p / invoke

I already found a similar question Here, but the solution is not elegant since it uses p/invoke to call a C++ code.

推荐答案

但是您可以通过将绘制模式设置为 OwnerDrawAll 并确定要呈现的内容来实现。

There might be an easier way; but you can do it by setting the draw mode to OwnerDrawAll and deciding what to render.

有一个很好的例子几乎完全符合您的需求:
http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/947aaded-6372-4253-8799-2b595f4a39b9/

There's a good example of almost exactly what you want here: http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/947aaded-6372-4253-8799-2b595f4a39b9/

这篇关于仅在子节点中选中复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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