473,325 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

listview: selected item vs. collection

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.
Nov 20 '05 #1
3 1578
If I understand you correctly, I think you could just use the
SelectedItems.Count property..
http://msdn.microsoft.com/library/de...classtopic.asp
and that would determine how many were selected.

HTH,

Bill
"tmaster" <le*******@travelmasterusa.com> wrote in message
news:d_************@fe2.columbus.rr.com...
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.

Nov 20 '05 #2
"tmaster" <le*******@travelmasterusa.com> schrieb
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
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "tmaster" <le*******@travelmasterusa.com> scripsit:
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
///

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: suz | last post by:
Hey, I have a collection with custom objects. That collection is bounded to a listview (I used the article of Lhotka). The listview is also sortable. I have also textboxes bound to the same...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
7
by: GTi | last post by:
I have a listview that with selected items. But I want to "reselect" items after a refresh. Each items have a uniqe value in the Tag object. After a refresh some new items may be added or removed...
13
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration...
7
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I'v been struggeling with removing selected items from a listview. Anyone that can give me a piece of code that does this? I am a newbee to this C# and cant figure it out.... Regards...
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
3
by: Matt Michael | last post by:
I have a listview control and a collection object right now that I'm trying to pass information to and from. Whenever I click on the checkbox, I want it to remove certain listview items and add...
5
by: John Devlon | last post by:
Hi, Does anyone know how to get a value of a second column of a selected item in Listview. I've create a listview and added this code Listview.Items.Clear() Listview.Columns.Clear()...
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
5
by: Joza | last post by:
Hi! I'm getting error when selecting items in ListView control, it says ArguementOutOfRangeExceptions. That happens in SelectIndexChange event. I have tryed with try...catch but there's no...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.