Programatically selecting items in a listview.

  • Thread starter Thread starter CJ Taylor
  • Start date Start date
C

CJ Taylor

I have the following code.

Dim lItem As ListViewItem

For Each lItem In Me.lv_Search.Items

lItem.Selected = True

Next

It doesn't highlight any items... sure the property is set... but it doesn't
seem to work... anyone else come across this..
 
* "CJ Taylor said:
I have the following code.

Dim lItem As ListViewItem

For Each lItem In Me.lv_Search.Items

lItem.Selected = True

Next

It doesn't highlight any items... sure the property is set... but it doesn't
seem to work... anyone else come across this..

Set the ListView's 'HideSelection' property to 'False'.
 
I had the same problem yes, besides what Herfried has suggested, try giving
the listview the focus. This is the case with treeview controls too (you are
probably using one too, he he). I was going nuts trying to figure out why I
could not selected, it turns out it was hiding the selection until it got
the focus.
 
selected = true works; you have to make sure the listview HideSelection
property is set to false other wise you won't see it until the control has
the focus.
 
I'd kiss you if your weren't so damn far away...

I suppose I could have read docs too.. but I do appreciate the help my
friend!

-CJ

BTW, I think that is 1) the first question of mine that has been answered in
this group in 3 weeks... 2) the fastest response time ever. =)
 
Yeah that Hide Selection is what got me.

I suppose its a good property name, but not quite descriptive enough... but
I dont know what else you could do unless you had something like
HideSelectedWhenLostFocus... but who wants a property like that?

Well... there is always intellisense =)

-CJ
 
* "CJ Taylor said:
Yeah that Hide Selection is what got me.

I suppose its a good property name, but not quite descriptive enough... but
I dont know what else you could do unless you had something like
HideSelectedWhenLostFocus... but who wants a property like that?

Well... there is always intellisense =)

Maybe it would be better if the value of the property would be set to
'False' by default.
 
Back
Top