TreeList.Selection Property

Gets the collection of selected nodes.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

Declaration

[Browsable(false)]
public TreeListMultiSelection Selection { get; }
<Browsable(False)>
Public ReadOnly Property Selection As TreeListMultiSelection

Property Value

Type Description
TreeListMultiSelection

A TreeListMultiSelection instance containing selected nodes.

Remarks

When a user navigates through the TreeList control, the TreeList.Selection collection contains a selected node. If the TreeListOptionsSelection.MultiSelect option is active and miltiple nodes are selected, the TreeList.Selection collection contains all selected nodes.

To enumerate elements of the collection, you can use the foreach (For Each in Visual Basic) statement, as the following code snippet demonstrates.


string columnName = "DEPARTMENT";
int i = 0;
foreach (DevExpress.XtraTreeList.Nodes.TreeListNode treeListNode in treeList1.Selection) {
    //Set a new value in the Department column for each selected node.
    treeListNode.SetValue(columnName, "Department" + i++.ToString());
}

Examples

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);
   }
}
See Also