ListView - Finding/Setting The selected Item

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Hello.

When you use the ListView1.Item(0).Selected = true, this addis the item to
items which show up int the ListView1.SelectedItems collection, but the item
is not highlighted in the control. How to you get the item highlighted and
how to you identify the specific element which is highlighted?

Thanks in advance for your assistance!!!!!!!!
 
Jim,
I think you want to set the hideselection property to false, but please read
the documentation first if it is want you want?
Cor
 
This property retains a form of highlighting after another control gets focus
(first part of my question!), but how how do you identify which item in the
control is highlighted after you leave, or for that matter are within the
control itself?
 
Hello,

Jim Heavey said:
When you use the ListView1.Item(0).Selected = true,
this addis the item to items which show up int the ListView1.
SelectedItems collection, but the item is not highlighted
in the control. How to you get the item highlighted and
how to you identify the specific element which is highlighted?

Have a look at the documentation for:

ListViewItem.Focused
ListView.HideSelection
ListView.FocusedItem

HTH,
Herfried K. Wagner
 
Jim,
The one before is hard to find, this one is more standard.
Listview1.Items(index).Selected =True
Cor
 
Jim,
Did not read it well,
First of all, the listview can have a multiselect
You have to do a for each loop to find which items are selected.

You can do it in more ways, I give 2 examples the first is for 2003 but with
a little change it works on 2002 too.
\\\\\
For Each item As ListViewItem In Listview1
If item.Selected = True Then
etc()
End If
Next
This is for 2002 and 203
dim i as integer
for i = 0 to listview1.Items.Count - 1
if lsvOntvang.Items(i).Selected = True then
etc()
End If
next
////
Cor
Dinner time
 
Thanks...
Cor said:
Jim,
Did not read it well,
First of all, the listview can have a multiselect
You have to do a for each loop to find which items are selected.

You can do it in more ways, I give 2 examples the first is for 2003 but with
a little change it works on 2002 too.
\\\\\
For Each item As ListViewItem In Listview1
If item.Selected = True Then
etc()
End If
Next
This is for 2002 and 203
dim i as integer
for i = 0 to listview1.Items.Count - 1
if lsvOntvang.Items(i).Selected = True then
etc()
End If
next
////
Cor
Dinner time
 
You can do it in more ways, I give 2 examples the first is for 2003 but
with
a little change it works on 2002 too.

For each works in 2002 as well doesn't it? An inline declaration doesn't
but you didn't do an inline declaration, or did you? Just interested...

Nick

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Nick,
The change is nothing for 2002
Dim item as listview
For Each item In Listview1
If item.Selected = True Then
next
I am happy we can communicatie so nice now.
Cor
 
Dim item as listview
For Each item In Listview1
If item.Selected = True Then
next

I thought so, I didn't know about the other method though, I presume 2003 is
capable of using the default property in the enumeration.
I am happy we can communicatie so nice now.

Ditto.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
2003 inline declarations are class.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
I think he means that they are good :-)

I do!! (Teesside term, where I live in England)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
Hello,

Nak said:
I think he means that they are good :-)

I don't mind not declaring inline, doesnt bother me either way.

The change breaks backward compatibility of sourcecode. I would not post
code with inline declarations for the next months.

Regards,
Herfried K. Wagner
 
I do!! (Teesside term, where I live in England)

Jordie huh?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Having problems with you job?
You're marriage is on the rocks?
You can't sleep at night?
You have a drink and drugs addiction?
You are sexually impotent?
Then enable Option Strict!
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Jordie? Not a chance. Teesside, not Newcastle :)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
 
Hello,

Tom Spink said:
Jordie? Not a chance. Teesside, not Newcastle :)
?!?

"Maybe it's a game called 'Punish the User'"

LOL

Regards,
Herfried K. Wagner
 
Back
Top