473,320 Members | 1,978 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,320 software developers and data experts.

Getting the selected listview item

My listview has two columns: Email Address & Email Address Type.

I've figured out how to populate it, but now I'm having trouble figuring out how to properly use the SelectedItems to get at the particular row that is double clicked. Can someone give me an example of how to get at the item, and subitems, of a selected row in a listview?

Thanks,

billy
Nov 20 '05 #1
2 3451
With Deft Fingers, billyb <bi****@discussions.microsoft.com> wrote:
My listview has two columns: Email Address & Email Address Type.
I've figured out how to populate it, but now I'm having trouble figuring out how to properly use the SelectedItems to get at the particular row that is double clicked. Can someone give me an example of how to get at the item, and subitems, of a selected row in a listview?


My Code here is used in a "SelectedIndexChanged" routine... but you should be
able to modify things for your need. My ListView is called "lvModDwgs". I
had to remove excess 'junk' from my strings (see the INFO lines).

I had my LV "multiselect" to TRUE... so I can click on more than 1 line. And
the 'first' item per each selected line ends up being 'TmpStrng1' that I list
in a ComboBox (just for info only).
Dim TmpStrng, TmpStrng1 As String
Dim LItem As ListViewItem
Dim LItems As ListView.SelectedListViewItemCollection
LItems = lvModDwgs.SelectedItems
' INFO - LItem.SubItems(2).ToString = "ListViewSubItem: {60-004}"
' Remove ListViewSubItem Gargage!

ComboBox1.Items.Clear()

For Each LItem In LItems

' Remove the Excess Junk from String
TmpStrng = LItem.SubItems(1).ToString
TmpStrng = Microsoft.VisualBasic.Right(TmpStrng, Len(TmpStrng) - 18)
TmpStrng = Microsoft.VisualBasic.Left(TmpStrng, Len(TmpStrng) - 1)
txbDwgTab.Text = TmpStrng

' Add Selected Names to ComboBox - Use this to Identify your Selections
TmpStrng1 = LItem.SubItems(0).ToString
TmpStrng1 = Microsoft.VisualBasic.Right(TmpStrng1, Len(TmpStrng1) - 18)
TmpStrng1 = Microsoft.VisualBasic.Left(TmpStrng1, Len(TmpStrng1) - 1)
ComboBox1.Items.Add(TmpStrng1)
Next
Regards,

Bruce
Nov 20 '05 #2
Thank you, Bruce! Will implement tonight.

"Mr. B" wrote:
With Deft Fingers, billyb <bi****@discussions.microsoft.com> wrote:
My listview has two columns: Email Address & Email Address Type.
I've figured out how to populate it, but now I'm having trouble figuring out how to properly use the SelectedItems to get at the particular row that is double clicked. Can someone give me an example of how to get at the item, and subitems, of a selected row in a listview?


My Code here is used in a "SelectedIndexChanged" routine... but you should be
able to modify things for your need. My ListView is called "lvModDwgs". I
had to remove excess 'junk' from my strings (see the INFO lines).

I had my LV "multiselect" to TRUE... so I can click on more than 1 line. And
the 'first' item per each selected line ends up being 'TmpStrng1' that I list
in a ComboBox (just for info only).
Dim TmpStrng, TmpStrng1 As String
Dim LItem As ListViewItem
Dim LItems As ListView.SelectedListViewItemCollection
LItems = lvModDwgs.SelectedItems
' INFO - LItem.SubItems(2).ToString = "ListViewSubItem: {60-004}"
' Remove ListViewSubItem Gargage!

ComboBox1.Items.Clear()

For Each LItem In LItems

' Remove the Excess Junk from String
TmpStrng = LItem.SubItems(1).ToString
TmpStrng = Microsoft.VisualBasic.Right(TmpStrng, Len(TmpStrng) - 18)
TmpStrng = Microsoft.VisualBasic.Left(TmpStrng, Len(TmpStrng) - 1)
txbDwgTab.Text = TmpStrng

' Add Selected Names to ComboBox - Use this to Identify your Selections
TmpStrng1 = LItem.SubItems(0).ToString
TmpStrng1 = Microsoft.VisualBasic.Right(TmpStrng1, Len(TmpStrng1) - 18)
TmpStrng1 = Microsoft.VisualBasic.Left(TmpStrng1, Len(TmpStrng1) - 1)
ComboBox1.Items.Add(TmpStrng1)
Next
Regards,

Bruce

Nov 20 '05 #3

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

Similar topics

2
by: Sam Johnson | last post by:
H how can I SET the selected item in a listview control Thank Sam
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...
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...
2
by: StriderBob | last post by:
In a list box, lbox1.SetSelected(0, True) or lbox1.SelectedIndex = 0 all work fine but how do you set the selected line in a ListView, is it possible? The ListView is being used in Details-View...
6
by: George | last post by:
Hi all, How can I get the value stored from the selected item and subitems of a listview? Thanks in advance, George
7
by: Mike Johnson | last post by:
How do I remove a item that's been selected from a listview? I'm using Visual Basic 2005 express edition. Thanks
3
by: sstein | last post by:
Hi, I am having a bit of trouble with some C# code. I can get it working in VB.NET, but can't seem to work out how to get the same code working in C#. I have a listview which stores information...
4
by: Bill-R | last post by:
I'm trying to convert a vb6 program to vb.net (vb2008 express) I have text data in a Listview Control I use a Textbox to enter characters to search the Listview When a Match is found, I use...
0
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to yellow. Trouble is, the selected item does not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.