Selecting Nodes
- 2 minutes to read
The TreeList control provides various options for selecting nodes via its OptionsSelection property. Refer to the TcxTreeListOptionsSelection class description for detailed information on these options.
Standard selection mode, a single selection, is enabled when the TreeList control’s OptionsSelection.MultiSelect property is set to False. Thus only one node can be selected at a time (the focused node). Focusing a record automatically selects it. You can use the following code to focus and select the top node within the TreeList control at the same time:
If the OptionsSelection.MultiSelect property is set to True, you can select multiple nodes at once. When a user clicks any node, it is focused and selected at the same time, however he/she can deselect the focused node by clicking it with the Ctrl key pressed.
To select/deselect multiple nodes, you can use the Selected property of the node object. The following code selects every second node in the TreeList control:
var
I: Integer;
begin
for I := 0 to cxTreeList1.Count - 1 do
cxTreeList1.Items[I].Selected := (cxTreeList1.Items[I].AbsoluteIndex mod 2 = 0);
end;
Use the SelectAll method to select all nodes in the TreeList control: