views:

121

answers:

3

I am using a Windows Forms TreeView control in my program. I would like to allow the user to select multiple nodes at the same level by dragging their mouse pointer around (also called a "lasso" selection). I don't think a standard TreeView allows that.

My question is what would be the best way to achieve this? Do I have to write custom selection behaviour of my own in perhaps a custom or derived control? Where do I start?

I don't need a detailed explanation. Just a small nudge in the right direction.

A: 

Windows typically does this by allowing shift-clicks, which selects all of the nodes between the two clicked nodes (inclusive).

Robert Harvey
+2  A: 

This is not going to be easy to do with a standard WinForms TreeView control. The TreeView control only supports single selection per tree. It is not possible to simultaneously select multiple nodes in the tree.

In order to get this behavior you would likely end up needing to create a very similar class to TreeView which allowed for multiple selection. Another option is to derive from TreeView and enable multiple selection by overriding specific behaviors. Here is an article on how to do the latter.

JaredPar
I understand the custom control approach to get multi-selection. What direction, you'd suggest, I should take in order to implement a "lasso" selection? Do I have to resort to GDI level custom drawing or is there an API or something that Windows exposes for this, which can make my job easier?
Frederick
@Frederick, I'm not a great person comment on that. My suggestion would be to open a separate new question purely focused on how to implement lasso selection on a generic WinForm control. That will likely yield better results.
JaredPar
Thanks Jared. I'll do just that.
Frederick
A: 

Consider implementing multiple selection in a control that supports multiple selection like listview. If you follow standards that most Windows users understand you'll end up with a solution that is easier to implement and easier to use.

If you really need something more elaborate you might need to consider developing a custom control.

Zamboni