By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,949 Members | 2,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,949 IT Pros & Developers. It's quick & easy.

Programatically selecting items in a listview.

P: n/a
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..
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
* "CJ Taylor" <no****@blowgoats.com> scripsit:
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'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
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.

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:vu************@corp.supernews.com...
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..

Nov 20 '05 #3

P: n/a
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.

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:vu************@corp.supernews.com...
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..

Nov 20 '05 #4

P: n/a
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. =)
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:et**************@TK2MSFTNGP10.phx.gbl...
* "CJ Taylor" <no****@blowgoats.com> scripsit:
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'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5

P: n/a
* "CJ Taylor" <no****@blowgoats.com> scripsit:
I'd kiss you if your weren't so damn far away...


;-)))

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
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
"Jared" <VB***********@email.com> wrote in message
news:vu************@corp.supernews.com...
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.

"CJ Taylor" <no****@blowgoats.com> wrote in message
news:vu************@corp.supernews.com...
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..


Nov 20 '05 #7

P: n/a
* "CJ Taylor" <no****@blowgoats.com-ctaylor_=-_at__==_mortonweldingdot_-0-_com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.