<p>I have a .Net desktop application with a TreeView as one of the UI elements.</p>

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

<p>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. </p>

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

[{'answer_id': 39156, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 3, 'selected': True, 'text': '<p>The default behavior of TreeView is that when the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.checkboxes%28VS.80%29.aspx" rel="nofollow noreferrer">Checkboxes</a> property is set to true, that checkboxes will be shown for all TreeNodes.</p>\n\n<p>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.<a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.stateimagelist%28VS.80%29.aspx" rel="nofollow noreferrer">StateImageList</a> property. Some sites to check out for more info:</p>\n\n<ul>\n<li>See <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3727125&amp;SiteID=1" rel="nofollow noreferrer">this post</a> to the MSDN forums that goes through an implementation similar to what you are attempting. </li>\n<li>CodeProject: <a href="http://www.codeproject.com/KB/tree/TriStateTreeViewSubmissio.aspx" rel="nofollow noreferrer">Tri-State TreeView</a></li>\n<li>CodeProject: <a href="http://www.codeproject.com/KB/tree/customstatetreeview.aspx?msg=1519062" rel="nofollow noreferrer">How to handle custom node state images in a TreeView (e.g. tristate checkboxes)</a></li>\n</ul>\n'}, {'answer_id': 39158, 'author': 'Skizz', 'author_id': 1898, 'author_profile': 'https://Stackoverflow.com/users/1898', 'pm_score': 1, 'selected': False, 'text': "<p>I had a very similar problem in an editor I wrote recently. In the end, I used the <code>TreeNode</code>'s <code>BackColor</code> property to determine the selection state of the node. I then wrote a handler for the <code>SelectionChanged</code> 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 <code>Generic::List&lt;&gt;</code> of the nodes that were currently selected to eliminate any tree searches.</p>\n"}, {'answer_id': 40442, 'author': 'Dmitry Shechtman', 'author_id': 3583, 'author_profile': 'https://Stackoverflow.com/users/3583', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.codeproject.com/KB/tree/Multiselect_Treeview.aspx" rel="nofollow noreferrer">MultiSelectTreeView</a>:</p>\n\n<blockquote>\n  <p>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.</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/39119', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/905/']