Board index » cppbuilder » Listview search fun

Listview search fun

Does anyone have any code that searches a listview for a match, search
meaning search all columns for the match.  I found a few snips while
browsing mers but none of them seem to work.  This is what i was
trying.

    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.");

It never finds anything at all......

 

Re:Listview search fun


How about this:

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

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

Binzhong

Quote
"Terry James" <t...@sundance.com> wrote in message news:3b1af22b$1_1@dnews...
> Does anyone have any code that searches a listview for a match, search
> meaning search all columns for the match.  I found a few snips while
> browsing mers but none of them seem to work.  This is what i was
> trying.

>     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.");

> It never finds anything at all......

Re:Listview search fun


Quote
Terry James <t...@sundance.com> wrote in message

news:3b1af22b$1_1@dnews...

Quote
> Does anyone have any code that searches a listview for a match,
search
> meaning search all columns for the match.  I found a few snips while

Since SubItems is a TStrings object, try something like

    if(ListView->Items->Item[x]->SubItems->IndexOf(FindText)>=0 ||
       ListView->Items->Item[x]->Caption == FindText)

but I'm sure there are other ways, too.  For example, the first
column, the Items, has it's own IndexOf method.

--
Timothy H. Buchman
========================================
City Center Theater New York NY
tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland newsgroup archives at:
http://www.mers.com/searchsite.html

Re:Listview search fun


Thanks guys it works now.
Quote

> Since SubItems is a TStrings object, try something like

>     if(ListView->Items->Item[x]->SubItems->IndexOf(FindText)>=0 ||
>        ListView->Items->Item[x]->Caption == FindText)

> but I'm sure there are other ways, too.  For example, the first

Re:Listview search fun


Is it possible to have the ability of a partial search on the
lsitview?  Lets say i have a few fields and in one field i have the
word

Borland Builder

If i search for builder it will not find it, i have to search for the
entire word for it to work.  Can this be modified to find just a
partial match?

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TListItem *FoundItem;

    for( int x = 0; x < ListView1->Items->Count; x++ )
    {
        for( int i = 0; i <
ListView1->Items->Item[x]->SubItems->Count; i++ )
        {
            if( ListView1->Items->Item[x]->SubItems->IndexOf(
Edit1->Text ) >= 0
                || ListView1->Items->Item[x]->Caption == Edit1->Text )
            {
                ListView1->Selected = ListView1->Items->Item[x];
                ListView1->SetFocus();
                return;
            }
        }
    }

    ShowMessage( Edit1->Text + " was not found." );

Quote
}

//--------------------------------------------------------------------
-------

Thanks..

Re:Listview search fun


Try using

for every fields string;
if(AnsiPos("builder")!=0){
    then it is there so keep the location and continue searching...

Quote
}

Craig
Quote
Terry James wrote:
> Is it possible to have the ability of a partial search on the
> lsitview?  Lets say i have a few fields and in one field i have the
> word

> Borland Builder

> If i search for builder it will not find it, i have to search for the
> entire word for it to work.  Can this be modified to find just a
> partial match?

> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>     TListItem *FoundItem;

>     for( int x = 0; x < ListView1->Items->Count; x++ )
>     {
>         for( int i = 0; i <
> ListView1->Items->Item[x]->SubItems->Count; i++ )
>         {
>             if( ListView1->Items->Item[x]->SubItems->IndexOf(
> Edit1->Text ) >= 0
>                 || ListView1->Items->Item[x]->Caption == Edit1->Text )
>             {
>                 ListView1->Selected = ListView1->Items->Item[x];
>                 ListView1->SetFocus();
>                 return;
>             }
>         }
>     }

>     ShowMessage( Edit1->Text + " was not found." );
> }
> //--------------------------------------------------------------------
> -------

> Thanks..

Other Threads