Board index » cppbuilder » TListView Find(Caption) method and highlighting the found item

TListView Find(Caption) method and highlighting the found item

Hello all,

to find a ListView item via its Caption theres the FindCaption(...) method.
I wonder what function to be used to search in other SubItems in the
TListView ??????? I need to find an item based on text in the 6e subitem.

Antoher question is about highlighting an TListView Item after a search. I
use the follwing code, this selects the found item  but this does NOT
higlight it.
How to realise that ?

in the OnDblClick function I use this code (that NOT highlights the item) :

       FoundItem = ((TListView *)Sender)->FindCaption(0,"01110027
TA",false,true,false);
        if ( FoundItem )
        {
          FoundItem->MakeVisible(false);
          ((TListView *)Sender)->Selected = FoundItem;   //  I thought this
would do it ?!?!?
        }

Thank you for your help,

Loek

 

Re:TListView Find(Caption) method and highlighting the found item


Quote
"Deelg" <m...@logera.com> wrote in message news:3c06bf1c$1_1@dnews...
> to find a ListView item via its Caption theres the FindCaption(...)
method.
> I wonder what function to be used to search in other SubItems in the
> TListView ??????? I need to find an item based on text in the 6e subitem.

There is no such function, sorry. You'll have to do the search yourself
manually by iterating through the items in a loop until you find the one
you're looking for.

For example, here's a variation of the FindData() method, for searching a
SubItem instead:

TListItem* __fastcall FindSubItem(TListView *ListView, int StartIndex, int
SubItemIndex, AnsiString Value, bool Partial, bool Inclusive, bool Wrap)
{
    TListItem *Item = NULL;

    if(Inclusive)
        StartIndex--;

    int count = ListView->Items->Count;
    for(int i = (StartIndex + 1); i < count; i++)
    {
        Item = ListView->Items->Item[i];
        if(Item != NULL)
        {
            AnsiString subvalue = Item->SubItems->Strings[SubItemIndex];

            if( (Partial && (subvalue.Pos(Value) == 1)) || (!Partial &&
(subvalue == Value)) )
                return Item;
        }
    }

    if(Wrap)
    {
        if(Inclusive)
            StartIndex++;

        for(int i = 0; i < StartIndex; i++)
        {
            Item = ListView->Items->Item[i];
            if(Item != NULL)
            {
                AnsiString subvalue = Item->SubItems->Strings[SubItemIndex];

                if( (Partial && (subvalue.Pos(Value) == 1)) || (!Partial &&
(subvalue == Value)) )
                    return Item;
            }
        }
    }

    return NULL;

Quote
}

Then you should be able to call it like this:

    TListItem *FoundItem = FindSubItem((TListView *)Sender, 0, 5,
"01110027TA", false, true, false);

Quote
> Antoher question is about highlighting an TListView Item after a search. I
> use the follwing code, this selects the found item  but this does NOT
> higlight it.
> How to realise that ?

Better to just set the TListItem's Selected property directly, no need to
use Sender:

    FoundItem->MakeVisible(false);
    FoundItem->Selected = true;

Gambit

Re:TListView Find(Caption) method and highlighting the found item


PERFECT !!!!!!!!!!!!! Thank you very much for the FindSubItem() routine !!
It does the job !!!!!!

BUT....  the question about highlighting the FoundItem does NOT work (my way
neither your way).
What is wrong ?

Loek

"Remy Lebeau" <gambi...@gte.net> schreef in bericht
news:3c06d4a1$1_1@dnews...

Quote

> > Antoher question is about highlighting an TListView Item after a search.
I
> > use the follwing code, this selects the found item  but this does NOT
> > higlight it.
> > How to realise that ?

> Better to just set the TListItem's Selected property directly, no need to
> use Sender:

>     FoundItem->MakeVisible(false);
>     FoundItem->Selected = true;

> Gambit

Re:TListView Find(Caption) method and highlighting the found item


Does your ListView have the focus at the time you try to highlight the item?
If not, does the ListView have it's HideSelection property set to true?

Gambit

Quote
"Deelg" <m...@logera.com> wrote in message news:3c082b57_1@dnews...
> BUT....  the question about highlighting the FoundItem does NOT work (my
way
> neither your way).
> What is wrong ?

Re:TListView Find(Caption) method and highlighting the found item


Thank YOU again......... stupid me, the ListView did NOT had its focus.
Now everything is ok.

Loek

"Remy Lebeau" <gambi...@gte.net> schreef in bericht
news:3c08323b$1_1@dnews...

Quote
> Does your ListView have the focus at the time you try to highlight the
item?
> If not, does the ListView have it's HideSelection property set to true?

> Gambit

> "Deelg" <m...@logera.com> wrote in message news:3c082b57_1@dnews...

> > BUT....  the question about highlighting the FoundItem does NOT work (my
> way
> > neither your way).
> > What is wrong ?

Other Threads