Board index » delphi » Find item in List View

Find item in List View

What's the quickest way to find an item in a List View.  I have a List View
with a few thousand items, and when I need to add to this list I need to
check that the item they are putting doesn't already exist.  I get round
this by looping through the list items checking the contract code of each
item.  I used to use a lost box and its IndexOf method which was very fast -
I can't get the equivalent to work with a list view.

Jim

 

Re:Find item in List View


Quote
In article <8uv2g2$b...@bornews.inprise.com>, James Poll wrote:
> What's the quickest way to find an item in a List View.  I have a List View
> with a few thousand items, and when I need to add to this list I need to
> check that the item they are putting doesn't already exist.  I get round
> this by looping through the list items checking the contract code of each
> item.  

The listview only offers a FindCaption method that will search column 0 (the
TListitem.caption) only. If you need to find things in other columns (the
subitems of the listitems) then you are reduced to doing a manual search using
a loop.

If you have a large number of items it may pay to go to an ownerdata-mode
listview. That would allow you to keep the data itself in a memory structure
of your choice, with lookup features as you need them.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads