• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 842
  • Last Modified:

Listview tag property: using a struct

I have a column in my listview control named "people"
When a user searches the listview control is populated with a list of people.
If the user double clicks a person in the listview control a popup appears containing information about the person.
To achieve this I hit the database and build a dataset containing the list of names and information associated with them.
I then iterate the dataset and fill the struct for each row in the dataset containing a person.

    Structure myStruct
        Dim intPersonID As Integer
        Dim intPhoneNum As Integer
    End Structure


'this is inside my button search click event
        For Each dr As DataRow In dsStatutes.Tables(0).Rows
            Dim item1 = New ListViewItem(CStr(dr.Item("display_name")), 0)

            myObject.intPersonID = dr.Item("person_id")
            myObject.intPhoneNum = dr.Item("phone_num")
            item1.tag = myObject

            Me.ListView1.Items.AddRange(New ListViewItem() {item1})
        Next

Later on, I want to access these items. How do I access the items in my struct?
You can only select one item in the listview control so I use the index of 0.
This accesses the tag but not the value in the struct I need.

       intPersonID= ListView1.SelectedItems(0).Tag

Thanks,
0
bertino12
Asked:
bertino12
1 Solution
 
AlexFMCommented:
You need to do casting:

intPersonID = CType(ListView1.SelectedItems(0).Tag, myStruct).intPersonID

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now