ListView Items Tag

  • Thread starter Thread starter Brian P. Hammer
  • Start date Start date
B

Brian P. Hammer

Hi all,

I am trying to get the tag of all items selected in a listbox. I cannot
seem to figure it out. I think I am getting stuck on the Dim and dimming it
as the correct item. Any help would be great.

Private Sub lstSelectAircraft_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lstSelectAircraft.SelectedIndexChanged
With lstSelectAircraft
Dim Item As Object '??????
For Each Item In lstSelectAircraft.SelectedItems
MsgBox(Item.tag)
Next
 
Hi,

Dim lvn As ListViewItem

For Each lvn In ListView1.Items

Debug.WriteLine(lvn.Tag)

Next

Ken
 
-----Original Message-----
Hi all,

I am trying to get the tag of all items selected in a listbox. I cannot
seem to figure it out. I think I am getting stuck on the Dim and dimming it
as the correct item. Any help would be great.

Private Sub lstSelectAircraft_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lstSelectAircraft.SelectedIndexChanged
With lstSelectAircraft
Dim Item As Object '??????
For Each Item In lstSelectAircraft.SelectedItems
MsgBox(Item.tag)
Next

Try ListViewItem :)
 
Hi Ken, This is what I thought but am receiving an error:

System.InvalidCastException occurred

Additional information: Specified cast is not valid.

Any idea?
 
Brian,

If you have option strict on try this.
Dim lvn As ListViewItem

For Each lvn In ListView1.Items

Dim strTag As String

strTag = CType(lvn.Tag, String)

Next

Ken

-----------------------
 
Thanks Ken

--
Thanks,
Brian P. Hammer
Ken Tucker said:
Brian,

If you have option strict on try this.
Dim lvn As ListViewItem

For Each lvn In ListView1.Items

Dim strTag As String

strTag = CType(lvn.Tag, String)

Next

Ken
 
Back
Top