Board index » cppbuilder » Searching listviews

Searching listviews

I have a TListView with 3 columns (0,1,2)  and a TEdit (Edit1) to search
on.  When the user types in the TEdit I want to search the ListView's
2nd column (1) for the value if Edit1 - I use the Edit1->OnChange.
There is a FindCaption method, but how do you tell it what column in the
ListView to search on, or is there a better way?
 

Re:Searching listviews


Quote
> on.  When the user types in the TEdit I want to search the ListView's
> 2nd column (1) for the value if Edit1 - I use the Edit1->OnChange.
> There is a FindCaption method, but how do you tell it what column in the
> ListView to search on, or is there a better way?

Simply look through all ListView items and check whether the first
subitem has the caption of Edit1:

  String FindText(Edit1->Text);
  for(int x = 0; x < ListView1->Items->Count; x++)
     if(ListView1->Items->Item[x]->SubItems->Strings[0]
        == FindText)
     {
        ShowMessage(FindText + " was found at " +
           ListView1->Items->Item[x]->Caption + ".");
        return;
     }

  ShowMessage(FindText + " was not found.");

I have never used FindCaption but my first impression is that it searches
only the first column.

--
Yoto Yotov

Other Threads