Solved

Listview tag property: using a struct

Posted on 2006-11-30
1
827 Views
Last Modified: 2007-12-19
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
Comment
Question by:bertino12
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 18045187
You need to do casting:

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

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question