473,402 Members | 2,061 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,402 software developers and data experts.

Select item from a Listview

M K
Using VS 2005

I have a listview that displays:

number, name, details (in that order)

when the user selects a row (single select) i want to retrieve each column
in a variable.

number is an int
name is a string
details is a string

i have searched the net and could not locate an example.

I am not trying to do this from the listview control but rather from a
button.

any help greatly appreciated.

Mark
May 17 '06 #1
4 12288
Use .SelectedItems[0] property and you will get ListViewItem object
http://msdn.microsoft.com/library/en...asp?frame=true
use .Subitems(0) - for number
use .Subitems(1) - for name
use .Subitems(2) - for details
ListViewItem lvItem = list..SelectedItems[0];
int number = (int)lvItem.SubItems[0] ;
string name = (string)lvItem.SubItems[1] ;
string details = (string)lvItem.SubItems[2] ;
I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 17 '06 #2
M K
thats progress but now i get the following:

Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'int'
Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'string'
Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'string'

"Galcho[MCSD.NET]" <ga****@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
Use .SelectedItems[0] property and you will get ListViewItem object
http://msdn.microsoft.com/library/en...asp?frame=true
use .Subitems(0) - for number
use .Subitems(1) - for name
use .Subitems(2) - for details
ListViewItem lvItem = list..SelectedItems[0];
int number = (int)lvItem.SubItems[0] ;
string name = (string)lvItem.SubItems[1] ;
string details = (string)lvItem.SubItems[2] ;
I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 18 '06 #3
M K
This did work.. i figured it out.. thanks for your help.

ListViewItem lvItem = lvTodo.SelectedItems[0];

int number = Convert.ToInt32(lvItem.SubItems[0].Text);

string name = lvItem.SubItems[1].Text;

string details = lvItem.SubItems[3].Text;

"M K" <sk*******@earthlink.net> wrote in message
news:Dl****************@newsread2.news.pas.earthli nk.net...
thats progress but now i get the following:

Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'int'
Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'string'
Error 1 Cannot convert type
'System.Windows.Forms.ListViewItem.ListViewSubItem ' to 'string'

"Galcho[MCSD.NET]" <ga****@gmail.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
Use .SelectedItems[0] property and you will get ListViewItem object
http://msdn.microsoft.com/library/en...asp?frame=true
use .Subitems(0) - for number
use .Subitems(1) - for name
use .Subitems(2) - for details
ListViewItem lvItem = list..SelectedItems[0];
int number = (int)lvItem.SubItems[0] ;
string name = (string)lvItem.SubItems[1] ;
string details = (string)lvItem.SubItems[2] ;
I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com


May 18 '06 #4
sorry, I missed to add .Text property to code

I am glad that I helped you

Regards.
Galin Iliev[MCSD.NET]
www.galcho.com

May 18 '06 #5

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

Similar topics

3
by: Chris | last post by:
I'm able to add a context menu to the right click on a listbox but it does not select the item in the listbox. I would like the context menu before it pops up to select the item that the mouse was...
1
by: Bob Geltz | last post by:
I am able to populate a ListView with several detail lines (several columns). When finished, I would like to pre-select the first item in the list (before the user interacts with the list). This...
5
by: Richard Bond | last post by:
I'm having a lot of trouble programatically selecting a listview item. How do you do this? These didn't work for me in the context of the sub below (that's trying to move up an Item in the...
1
by: Shane | last post by:
I have a text box select items in a listview as text is being typed into the text box. I get the select bar to move correctly in the Listview control. If the user presses the down or up key in...
4
by: Joerg Trumpfheller | last post by:
Hey folks, I have a problem with selecting an item in a listview control from outside. Listview items are binded with unique ids. I got now an id from another control and want to select the...
3
by: rlg | last post by:
We have C# 2005 multi-threaded app. A background thread is processing data and periodically updating the contents of a ListView. Sometimes, the user clicking on a ListView item will not select...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
0
by: =?Utf-8?B?Q2FibGVHdXk=?= | last post by:
If I have an unsorted listview I know I can select the first Item by ListView.Items.Selected = true. How do I select the first item in a sorted listview? Thanks. CableGuy
1
by: polocar | last post by:
Hi, I'm using Visual C# 2005 (part of Visual Studio 2005 Professional Edition), and I have the following problem: I populate a ListView object with several items, and at the end of this process I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.