listview: selected item vs. collection

T

tmaster

In a listview (named lvwToDo), I understand how to reference a single
selected item from the SelectedItems collection, but is there a more direct
way if MultiSelect is set to false and you know there is only one item
selected? In other words, is there a better way other than the following
loop?

Dim litem As ListViewItem

For Each litem In lvwToDo.SelectedItems
...do whatever with litem
Next

Thanks again.
 
A

Armin Zingler

tmaster said:
In a listview (named lvwToDo), I understand how to reference a
single selected item from the SelectedItems collection, but is there
a more direct way if MultiSelect is set to false and you know there
is only one item selected? In other words, is there a better way
other than the following loop?

Yes: Don't write a loop.
Dim litem As ListViewItem

For Each litem In lvwToDo.SelectedItems
...do whatever with litem
Next

if lvwTodo.SelectedItems.count=1 then
lvwTodo.SelectedItems(0).<member>
end if
 
H

Herfried K. Wagner [MVP]

* "tmaster said:
In a listview (named lvwToDo), I understand how to reference a single
selected item from the SelectedItems collection, but is there a more direct
way if MultiSelect is set to false and you know there is only one item
selected? In other words, is there a better way other than the following
loop?

\\\
Me.ListView1.SelectedItems(0).Text = Foo
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top