TreeList.Selection Property
Gets the collection of selected nodes.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.1.dll
NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList
Declaration
Property Value
Type |
---|
DevExpress.XtraTreeList.TreeListSelection |
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());
}
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.
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);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Selection property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.