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 :-)
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 ;-)
IndexOf method of Listboxes perform 2 kinds of searches:
- If your data is sorted, then make a binary search (look in the item sited at the 50% of the data, if is greater than the string searched, look for the item placed at 25%, if is lower, look for the item places at 75% and rep and rep until the end).
- If you data is not sorted, IndexOf makes an search

- In a ListView, you can search data with the FindCaption method, than calls to the Windows Api: ListView_FindItem so... is a fast way...
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);
ls: TStringlist;
lFound: boolean;

for li:=0 to pred(listview1.items.count) do

Untested and not debugged
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

wildzeroAuthor Commented:
Findcaption will work great, is there any source code?
Sourcecode for make a FindCaption? :?
  anItem:=ListView1.FindCaption(0, 'TheCaption', True, True, True);
  if not (anItem = nil) then
    // found it

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wildzeroAuthor Commented:
Thanks alot!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.