vcl-170101-expressquantumtreelist-concepts-selecting-nodes.md
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 cxTreeList1.TopNode <> nil then
cxTreeList1.TopNode.Focused := True;
if (cxTreeList1->TopNode != null)
cxTreeList1->TopNode->Focused = true;
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;
for (int i = 0; i < cxTreeList1->Count; i++)
cxTreeList1->Items[I]->Selected = (cxTreeList1->Items[I]->AbsoluteIndex % 2 == 0);
}
Use the SelectAll method to select all nodes in the TreeList control:
cxTreeList1.SelectAll;
cxTreeList1->SelectAll();