wildzero
asked on
Find item in listview (without For statement)
Hi there,
Is there a quick way I do can do a search in a list view?
With a listbox you can do indexof to see if an item exists, the listview also has an indexof function but doesn't work the same.
Thanks :-)
Is there a quick way I do can do a search in a list view?
With a listbox you can do indexof to see if an item exists, the listview also has an indexof function but doesn't work the same.
Thanks :-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
as RadikalQ3 says you can use Listview1.FindCaption but this will only find matches in the caption property of the listview, not in any subitems. If you want to search in subitems then the only way is to use a loop.
If you are searching in the subitsm the you need something like
procedure Find (FindStr: string);
var
ls: TStringlist;
lFound: boolean;
begin
for li:=0 to pred(listview1.items.count ) do
begin
lFound:=listview.items[li] .subitems. indexof(Fi ndStr)>-1;
end;
Untested and not debugged
If you are searching in the subitsm the you need something like
procedure Find (FindStr: string);
var
ls: TStringlist;
lFound: boolean;
begin
for li:=0 to pred(listview1.items.count
begin
lFound:=listview.items[li]
end;
Untested and not debugged
ASKER
Findcaption will work great, is there any source code?
Sourcecode for make a FindCaption? :?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks alot!
i := 0;
while (I<listbox1.items.count) and (listbox1.items[i].Caption
if i<listbox1.items.count then //found
....
meikl ;-)