Example: Column.Focused, Node.Focused, Node.GetPrevVisible, Node.GetPrev, Node.GetNextVisible, Node.GetNext
- 2 minutes to read
The following sample searches a tree list column’s values for a search string. The SearchByColumn method accepts the following parameters:
AColumn specifies the column to be searched.
AText provides the search string.
AForward specifies the direction of the search. If set to True, the search is forward; otherwise, the search goes backward.
AVisibleOnly specifies whether the search engine should only use the visible cells of the column. If set to True, the search engine only examines the visible cells within the column; otherwise, all the values of the column are searched for the search string (AText parameter). In the latter case, if the engine finds a match, the node to which the match belongs is made visible (by expanding all its parent nodes).
procedure SearchByColumn(AColumn: TcxTreeListColumn; AText: String; AForward, AVisibleOnly: Boolean);
var
ANode: TcxTreeListNode;
begin
ANode := cxTreeList.FocusedNode;
repeat
if Pos(UpperCase(AText), UpperCase(ANode.Texts[AColumn.ItemIndex])) <> 0 then
begin
// ensure that the column and the node that contains the match are visible
AColumn.Focused := True;
AColumn.MakeVisible;
ANode.Focused := True;
ANode.MakeVisible;
Break;
end;
// only taking visible nodes into consideration
if AVisibleOnly then
begin
if AForward then
ANode := ANode.GetNextVisible
else
ANode := ANode.GetPrevVisible;
end
else
begin
if AForward then
ANode := ANode.GetNext
else
ANode := ANode.GetPrev;
end;
until ANode = nil
end;