Solved

Listview tag property: using a struct

Posted on 2006-11-30
1
821 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
Comment Utility
You need to do casting:

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

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now