Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow multi-select in a .NET TreeView

Tags:

I'm stuck in .NET 2.0 Windows Forms.

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

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

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

like image 424
Darcy Casselman Avatar asked Oct 15 '08 19:10

Darcy Casselman


People also ask

Which event of the TreeView control is used for multiple selection of nodes?

TreeView supports to select the multiple nodes by specifying allowMultiSelection as true. It allows you to select more than one nodes in TreeView.

How do you edit TreeView?

The TreeView allows you to edit nodes by setting the allowEditing property to true. To directly edit the nodes in place, double click the TreeView node or select the node and press F2 key. When editing is completed by focus out or by pressing the Enter key, the modified node's text saves automatically.

What is TreeView in C#?

The TreeView control contains a hierarchy of TreeViewItem controls. It provides a way to display information in a hierarchical structure by using collapsible nodes . The top level in a tree view are root nodes that can be expanded or collapsed if the nodes have child nodes.


1 Answers

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.

like image 79
Jeff Yates Avatar answered Sep 21 '22 09:09

Jeff Yates