Link to home
Start Free TrialLog in
Avatar of wildzero
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 :-)
Avatar of kretzschmar
kretzschmar
Flag of Germany image

what about a while instaed of for like

i := 0;
while (I<listbox1.items.count) and (listbox1.items[i].Caption <> YourMatchStr) do inc(I);
if i<listbox1.items.count then //found
....


meikl ;-)
SOLUTION
Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pcsentinel
pcsentinel

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(FindStr)>-1;
end;


Untested and not debugged
Avatar of wildzero

ASKER

Findcaption will work great, is there any source code?
Sourcecode for make a FindCaption? :?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks alot!