Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Select a node's children

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