ListView Items Tag

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
 
K

Ken Tucker

Hi,

Dim lvn As ListViewItem

For Each lvn In ListView1.Items

Debug.WriteLine(lvn.Tag)

Next

Ken
 
M

Marijn Ros

-----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 :)
 
B

Brian P. Hammer

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

System.InvalidCastException occurred

Additional information: Specified cast is not valid.

Any idea?
 
K

Ken Tucker

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

-----------------------
 
B

Brian P. Hammer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top