Board index » cppbuilder » TListView: How to always keep one Item selected ?

TListView: How to always keep one Item selected ?

Hi

I want one of the items in my TListView to be selected.  There should always be one selected.  If I click in the ListView, but not on any item, the selection disappears.
Is there any way to force the TListView to keep one item selected ?

The listView->Selected should NEVER be NULL !! (unless there are no items in the list).

Regards!
Per Kare Foss

 

Re:TListView: How to always keep one Item selected ?


There is an attribute that can be set at the API level and I am assuming its present at the VCl level too.

Craig

Quote
Per K?re Foss wrote:
> Hi

> I want one of the items in my TListView to be selected.  There should always be one selected.  If I click in the ListView, but not on any item, the selection disappears.
> Is there any way to force the TListView to keep one item selected ?

> The listView->Selected should NEVER be NULL !! (unless there are no items in the list).

> Regards!
> Per Kare Foss

Re:TListView: How to always keep one Item selected ?


Quote
Per K?re Foss wrote in message <1103_991425791@gpc-19>...
>Hi

>I want one of the items in my TListView to be selected.  There should

always be one selected.  If I click in the ListView, but not on any item,
the selection disappears.

Quote
>Is there any way to force the TListView to keep one item selected ?

>The listView->Selected should NEVER be NULL !! (unless there are no items
in the list).

Per,
First, set ListView1's HideSelection to false, so it always shows the
current selection if the list view loses focus.

In your form, add a private data member:
TListItem* (FCurrentListItem);

In you form's OnShow, set
FCurrentListItem = ListView1->ListItems->ListItem[0]; // check to make sure
there IS at least one item in the list first!

In ListView1Changing,
FCurrentListItem = ListView1->Selected;

In ListView1Change,
if(ListView1->Selected == NULL) // if the 'click' was NOT on a list item
    ListView1->Selected = FCurrentListItem; // then set the selected item to
the last one that was selected\
else
    FCurrentListItem = ListView1->Selected; // otherwise, save the new
'current' item.

Hope this helps,
Dave

Other Threads