views:

2517

answers:

3

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?

+3  A: 

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:

Yaakov Ellis
+1  A: 

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.

Skizz

Skizz
A: 

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.

Dmitry Shechtman