views:

5260

answers:

6

I'm stuck in .NET 2.0 Windows Forms.

It doesn't look like the ability to select multiple nodes doesn't exist in the standard TreeView control.

I'm trying to do this for context menu selection. So check boxes aren't an acceptable UI paradigm here.

What's the best way to provide that very necessary functionality?

+1  A: 

TreeView.CheckBoxes

Will
That's not really what I'm looking for. Every other tree view in Windows allows you to ctrl-click select multiple entries. And driving a context menu off of checky boxes doesn't make any sense.
Darcy Casselman
I can't find an example of a ctrl-click tree view anywhere in the "standard" Windows OS environment. Can you provide an example? I agree that a context menu from checks isn't very sensible, but I don't think expecting users to ctrl+click is either. (A lot of users have trouble with that, in my exp.)
John Rudy
For the standard Windows Forms treeview, that's how you select more than one node in the tree.
Will
Okay, "standard" may be the wrong word. Take, for example, the Solution Explorer in Visual Studio.
Darcy Casselman
The problem is that the "standard" controls you get to play with and use for free (the ones that ship with VS) aren't necessarily the ones you see actually being used in Windows. You have three options 1) checkboxes 2) write your own 3) buy one. Sucks, I know. Its easy to do in WPF!
Will
+2  A: 
Jay Mooney
+3  A: 

We did this in a WTL project once, but the basic work needed is the same for .NET. To achieve a multiple selection tree control, you will need to draw the tree items yourself and override the keyboard and mouse handling. You will also need to maintain your own list of items that are selected.

Don't forget to consider selection rules (are parents and children allowed, for example), and don't forget to implement the keyboard shortcuts including selection using Ctrl, Shift, and Ctrl+Shift, as well as the Spacebar for selecting/deselecting.

Jeff Yates
+1  A: 

You might look at a 3rd party solution. The Infragistics tree does this. Not free, but the time spent trying to find a solution isn't really free, either.

Jon B
-1 : took me much less than 5 minutes to find a simple free one and implement it in my solution. Here are 2 samples: http://www.codeproject.com/KB/tree/MWTreeViewv2010.aspx, http://www.arstdesign.com/articles/treeviewms.html. Not perfect, but works and could be improved if you know your way around it.
synhershko
+1  A: 

Please check this out:

Multi Select TreeView from CodeProject, by Andrew D. Weiss

Hope it helped.

Mickey

Mickey
+1  A: 

You can try the IntegralUI TreeView control from Lidor Systems. There are 4 modes of selecting nodes: None, One, MultiSimple and MiltiExtended.

Lokey