Example: Node.Selected, TreeList.GetSelections, OptionSelection.MultiSelect
- 2 minutes to read
The following sample selects all the nodes within the control that have identical values within a column. The index of the column is passed via the AItemIndex parameter. You can pass the index of the focused column as a parameter (see FocusedColumn). Additionally, you can use the OnFocusedColumnChanged event to select the “same” nodes when the end-user selects columns within the control.
Note that the MultiSelect option should be enabled.
procedure SelectIdenticalNodes(AItemIndex: Integer);
var
I, J: Integer;
AValue: String;
ASelectedNodes: TList;
AValueList: TStringList;
begin
if not cxTreeList.OptionsSelection.MultiSelect then Exit;
ASelectedNodes := TList.Create;
AValueList := TStringList.Create;
try
cxTreeList.GetSelections(ASelectedNodes);
for I := 0 to ASelectedNodes.Count - 1 do
begin
AValue := TcxTreeListNode(ASelectedNodes[I]).Texts[AItemIndex];
if AValueList.IndexOf(AValue) = -1 then
AValueList.Add(AValue);
end;
cxTreeList.BeginUpdate;
try
for I := 0 to cxTreeList.Nodes.Count - 1 do
begin
AValueList.Sort;
AValue := cxTreeList.Nodes[I].Texts[AItemIndex];
if AValueList.Find(AValue, J) then
cxTreeList.Nodes[I].Selected := True;
end;
finally
cxTreeList.EndUpdate;
end;
finally
AValueList.Free;
ASelectedNodes.Free;
end;
end;