Board index » delphi » TListview : How to prevent 'Selected = nil'.

TListview : How to prevent 'Selected = nil'.

I have a TListview. I want to always have at least one item selected.
That way I can rely on MyListView.Selected having a value.
If the user clicks on a blank spot in the listview I would like the last selected Item to keep
beeing selected.
I guess this is easy, but I can't get it to work. I tried using OnSelectItem but it does not trigger
when Selected = nil.

Any help would be welcome. Thanks in advance!

--
Yours

Poul Bak
(Remove 'NOSPAM.'  from my e-mail address to answer directly)

"Experience is the creative mind's worst enemy !"

 

Re:TListview : How to prevent 'Selected = nil'.


Quote
"Poul Bak" <NOSPAMpoul.s....@get2net.dk> wrote in message

news:3bb2684a_2@dnews...

Quote
> I have a TListview. I want to always have at least one item selected.

Poul,

Never do this!!!

Always check for nil,  because the selection may be nil for a veriety of
reasons.  For example,  the list might be empty.

If an exception occurs during list loading,  and you don't trap the
exception,  then chances are your list may be empty and selection will be
nil.

There are probably lots of other examples I could give,  but the bottom line
is that you should always make this check.

Stan.

Other Threads