I need to fill a ListBox with data, NOT related to a database. I would like
presenting the description in the ListBox, and an ID needs to be available
when an item is selected in the ListBox.
How can i do this (using an Array? using a second invisible ListBox?) ???
Thanks for any help?
Guy
"Guy Dillen" <guy_dillen@nospam.hotmail.com> schrieb:
>I need to fill a ListBox with data, NOT related to a database. I would like
>presenting the description in the ListBox, and an ID needs to be available
>when an item is selected in the ListBox.
>
> How can i do this (using an Array? using a second invisible ListBox?) ???
\\\
Dim p As New Person()
p.Name = "Pink Panther"
p.Age = 22
Me.ComboBox1.Items.Add(p)
' Test.
MessageBox.Show(DirectCast(Me.ComboBox1.Items.Item(0), Person).ToString())
.
.
.
Public Class Person
Private m_Name As String
Private m_Age As Integer
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal Value As String)
m_Name = Value
End Set
End Property
Public Property Age() As Integer
Get
Return m_Age
End Get
Set(ByVal Value As Integer)
m_Age = Value
End Set
End Property
Public Overrides Function ToString() As String
Return Me.Name & " (" & Me.Age.ToString() & ")"
End Function
End Class
///
Alternatively, you can use a bound combobox:
\\\
With Me.ListBox1
' This can be an 'ArrayList' or array too, for example!
.DataSource = Database.FindPeople(...)
.DisplayMember = "Name"
.ValueMember = "Age"
End With
///

Signature
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/