"Steve Enzer" <enzer@frontiernet.net> schrieb:
[quoted text, click to view] > I'm a VB6 programmer just getting my feet wet in VB .NET and I have a
> question regarding the Listbox and Combobox.
>
> In VB6 I could set the ItemData property via code while adding items to
> the control. In .NET, it appears that SelectedValue has replaced
> ItemData. I've learned how to use this property when binding to a data
> table, but I have found no way to assign data values via code when using
> the Add method to fill the Items collection for the control.
\\\
Dim p As New Person()
p.Name = "Pink Panther"
p.Age = 22
Me.ComboBox1.Items.Add(p)
' Test.
MsgBox(DirectCast(Me.ComboBox1.Items(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
///
--
M S Herfried K. Wagner
M V P <URL:
http://dotnet.mvps.org/> V B <URL:
http://classicvb.org/petition/>