Getting the selected listview item

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
With Deft Fingers said:
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
 
Thank you, Bruce! Will implement tonight.

Mr. B said:
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
 
Back
Top