Checkboxes only in Children Nodes?

2020-04-08 07:35发布


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 :


Here is a code sample :

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);

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


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

There's a good example of almost exactly what you want here: