Selecting CheckBoxes=true on the treeview puts checkboxes on every node. I only want them on the leaves? How?
Asked
Active
Viewed 3,472 times
1
-
2http://stackoverflow.com/questions/4826556/treeview-remove-checkbox-by-some-nodes – Niranjan Singh Nov 16 '11 at 05:45
-
This has been already answered here: https://stackoverflow.com/questions/6093467/adding-the-check-boxes-in-the-treeview-in-c-sharp Look for reference to http://dotnetfollower.com/wordpress/2011/05/winforms-treeview-hide-checkbox-of-treenode/ – Fernando Gonzalez Sanchez Oct 21 '13 at 22:31
1 Answers
2
I think you need to implement an ownerdraw event handler for the nodes like this:
treeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
treeView.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeView_DrawNode);
private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if(NodeWithCheckBox(e.Node))
{
// draw entry with checkbox
e.DrawDefault = false;
}
else
{
e.DrawDefault = true;
}
}

Steve
- 1,072
- 11
- 28