|
-
Dec 17th, 2002, 04:07 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Custom objects to populate Listview Items collection
Hi
I have created a class by inheriting the ListViewItem and then added some new properties. I then use this inherited class to define objects that I add to my listview. My question is, how do I pick up the new properties when I click on an item.
VB Code:
Class CMyItem
inherits ListViewItem
Public ComponentName as string
Public AccessID as Long
Public Sub New(byval agStrCompName as string, byval agLngAccessID as Long)
ComponentName = agStrCompName
AccessID = agLngAccessID
End Sub
End Class
' In a form I add items to my listview as follows
Dim objItem as CMyItem
objItem = new CMyItem("ComponentA", 16)
ListView1.Add(objItem)
Private Sub ListView1_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles ListView1.Click
' How do I pick up the Componentname property from my custome made item that populates the listview
End Sub
Now I could be using an incorrect approach, I would welcome any alernatives. Just bear in mind that I want to populate my listview with custom made objects that would expose my new properties.
Thanks for your help.
Last edited by Mr.No; Dec 17th, 2002 at 06:01 AM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Dec 17th, 2002, 04:54 AM
#2
Registered User
I took the liberty to add 2 properties as well. 
Code:
Class CMyItem
Inherits ListViewItem
Dim m_ComponentName As String
Dim m_AccessID As Long
Public Sub New(ByVal agStrCompName As String, _
ByVal agLngAccessID As Long)
ComponentName = agStrCompName
AccessID = agLngAccessID
End Sub
Property ComponentName()
Get
Return m_ComponentName
End Get
Set(ByVal Value)
m_ComponentName = Value
End Set
End Property
Property AccessID()
Get
Return m_AccessID
End Get
Set(ByVal Value)
m_AccessID = Value
End Set
End Property
End Class
to get something back you can do something like this.....
Code:
MsgBox(DirectCast(ListView1.SelectedItems.Item(0), CMyItem).AccessID)
-
Dec 17th, 2002, 05:38 AM
#3
Thread Starter
Fanatic Member
[RESOLVED] Custom objects to populate Listview items collection
Thanks Athley.
It works
Last edited by Mr.No; Dec 17th, 2002 at 05:51 AM.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|