Hi, i have a listview in vsReport, i found this code on torry:
It works very good, the only problem is you need to type an exact match string.
so i need to know:
1) how can i search and find any part of the string?
for example if in column 2 i have this subitem: "Hello Tek Tips", if i search "llo" it should pick up the subitem.
2) if there is better code please post it.
Thanks!
Code:
// Function to search items and select if found
// Funktion, um Items zu suchen unda falls gefunden, sie danach markieren
procedure LV_FindAndSelectItems(lv: TListView; const S: string; column: Integer);
var
i: Integer;
found: Boolean;
lvItem: TListItem;
begin
Assert(Assigned(lv));
Assert((lv.ViewStyle = vsReport) or (column = 0));
Assert(S <> '');
for i := 0 to lv.Items.Count - 1 do
begin
lvItem := lv.Items[i];
if column = 0 then
found := AnsiCompareText(lvItem.Caption, S) = 0
else if column > 0 then
begin
if lvItem.SubItems.Count >= Column then
found := AnsiCompareText(lvItem.SubItems[column - 1], S) = 0
else
found := False;
end
else
found := False;
if found then
begin
lv.Selected := lvItem;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lvItem: TListItem;
begin
// in der Spalte subitem[0] den Text aus Edit1 suchen
LV_FindAndSelectItems(ListView1, Edit1.Text, 1);
ListView1.SetFocus;
end;
It works very good, the only problem is you need to type an exact match string.
so i need to know:
1) how can i search and find any part of the string?
for example if in column 2 i have this subitem: "Hello Tek Tips", if i search "llo" it should pick up the subitem.
2) if there is better code please post it.
Thanks!