ListBox problem

G

Guy Dillen

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
 
H

Herfried K. Wagner [MVP]

Guy Dillen said:
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
///
 

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

Top