A newer version of this page is available. Switch to the current version.

Node Selection

  • 4 minutes to read

You can enable node selection, allowing multiple nodes to be selected. Selected nodes are highlighted in a specific manner, indicating their states. You can access these nodes in code and process them, if required.

Don't confuse selected nodes with the focused node. The focused node specifies the node containing focus. There is only one focused node. By default, in node selection mode, when a node is focused by an end-user, it's automatically selected. However, the end-user can click the focused node with the CTRL key pressed to deselect it. See Focus and Navigation to learn more.

Selected Nodes Overview

To enable node selection, set the TreeListOptionsSelection.MultiSelect property to true. In node selection mode, you or an end-user can select contiguous and non-contiguous node ranges.

Selected nodes are highlighted in a specific manner. You can use the TreeListAppearanceCollection.SelectedRow property to customize the appearance of selected nodes. The TreeListAppearanceCollection.HideSelectionRow property specifies the appearance of selected nodes, when the Tree List control is not focused.

TreeList_selection

If the TreeListOptionsBehavior.KeepSelectedOnClick option is active, the selection is preserved while editing cells within the selected nodes.

Selecting Nodes Using the Mouse and Keyboard

To select multiple nodes using the mouse, an end-user must use the SHIFT or CTRL key. To select a continuous range of nodes, click the first node of the range. Then, hold the SHIFT key down and click the last node of the range. To select a specific node (and add it to the existing selection), click it with the CTRL key pressed.

Clicking a node while holding the CTRL key down toggles the node's selected state, changing the state from selected to deselected, and vice-versa.

If the TreeListOptionsSelection.UseIndicatorForSelection property is enabled, the node indicator panel can be used to select nodes. In this instance, an end-user can drag with the mouse along the indicator to select a range of nodes or click a specific node's indicator cell while holding down the CTRL key to toggle only this node's selection state.

For other methods of selecting nodes, see Selecting Nodes.

Work with Selection in Code

You can work with selection in code via the TreeList.Selection property. This property allows you to access the currently selected nodes and select or deselect certain nodes.

To respond to change in node selection, you can handle the TreeList.SelectionChanged event.

Example

The following code demonstrates how to traverse through selected nodes, in order to expand them. The selected nodes are accessed via the TreeList.Selection property.

for(int i = 0; i < treeList1.Selection.Count; i++) {
   treeList1.Selection[i].Expanded = true;
}

Example

The following code shows how to select children of a specific node. In the example, nodes are selected via the TreeListMultiSelection.Set method of the TreeList.Selection object.

The image below shows the result of selecting a Sales and Marketing node's children.

MultiSelect_Children

using DevExpress.XtraTreeList.Nodes;

TreeListNode node = treeList1.FindNodeByFieldValue("Department", "Sales and Marketing");
if (node != null) {
    ArrayList selectedNodes = new ArrayList();
    selectChildren(node, selectedNodes);
    treeList1.Selection.Set(selectedNodes);
}

void selectChildren(TreeListNode parent, ArrayList selectedNodes) {
   IEnumerator en = parent.Nodes.GetEnumerator();
   TreeListNode child;
   while(en.MoveNext()) {
      child = (TreeListNode)en.Current;
      selectedNodes.Add(child);
      if(child.HasChildren) selectChildren(child, selectedNodes);
   }
}

Member Tables

End-User Capabilities

See Also