By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,369 Members | 1,533 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,369 IT Pros & Developers. It's quick & easy.

Getting the selected listview item

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.