Assigning non-visible IDs to a listbox

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

Is there no easy way to emulate the ItemData property from VB6? Accepting
that list items are of type object instead of string, how best to assign
say, a non-visible table ID to each item in the listbox (that is, without
binding)?
 
* "Earl said:
Is there no easy way to emulate the ItemData property from VB6? Accepting
that list items are of type object instead of string, how best to assign
say, a non-visible table ID to each item in the listbox (that is, without
binding)?

\\\
Dim p As New Person()
p.Name = "Pink Panther"
p.Age = 22

Me.ComboBox1.Items.Add(p)

MessageBox.Show( _
DirectCast(Me.ComboBox1.Items.Item(0), Person).ToString() _
)
..
..
..
Public Class Person
Private m_strName As Object
Private m_intAge As Integer

Public Property Name() As String
Get
Return m_strName
End Get
Set(ByVal Value As String)
m_strName = Value
End Set
End Property

Public Property Age() As Integer
Get
Return m_intAge
End Get
Set(ByVal Value As Integer)
m_intAge = Value
End Set
End Property

Public Overrides Function ToString() As String
Return m_strName & " (" & m_intAge.ToString() & ")"
End Function
End Class
///
 
Thanks for the suggestion. I don't really see how I can use Tag without
subclassing the listbox though.
 
Yes .... if there is no shorter way, it appears better to create a new class
for the data than for to subclass the listbox. The other approach I used was
to match on the text and/or split to get the matching strings -- ugly.

Thanks.
 

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

Back
Top