Wednesday, March 21, 2007

function FindListViewItem(lv: TListView; const S: String; column: integer): TListItem;
var
i: integer;
found: Boolean;
begin
Assert(Assigned(lv));
Assert((lv.viewstyle = vsReport) or (column = 0));
Assert(S <> '');
for i := 0 to lv.Items.Count - 1 do
begin
Result := lv.Items[i];
if column = 0 then
found := AnsiCompareText(Result.Caption, S) = 0
else if column <= Result.SubItems.Count then
found := AnsiCompareText(Result.SubItems[column - 1], S) = 0
else
found := False;
if found then
Exit;
end;
Result := nil;
end;

procedure TForm1.Button1Click(Sender: TObject);
var lItem:TListItem;
begin
litem:=FindListViewItem(ListView1,'hledaný text',1);
if lItem<>nil then ShowMessage(lItem.Caption+' pozice:'+IntToStr(lItem.Index));
end;