Thanks! I had tried setting the DisplayMember, but I hadn't tried using
true properties instead of public variables. I had no idea there was such a
difference. Ironically, I always use full properties in my classes for
professional work. I was "cheating" here because I was working on a quick,
throwaway application to test a concept.
Anyway, thanks again for the help.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
Hi,
You can bind to an arraylist and show any property in the class.
Change you class to this.
Public Class test
Dim mVal As Integer
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Property Value() As Integer
Get
Return mVal
End Get
Set(ByVal Value As Integer)
mVal = Value
End Set
End Property
End Class
Dont forget to set the display member
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
cbo.displaymember = "Value"
End Sub
Ken
---------------------
"Adam J. Schaff" <ab****@adelphia.net> wrote in message
news:ur**************@TK2MSFTNGP14.phx.gbl...
I am forgetting something obvious, I think. I have a form with a combobox
on
it. I place the code (below) in the form. Instead of populating the
dropdown
with 0 and 1, as I expected, it populates it with two rows, each
containing
the string "MyProject.Form1+test"
What am I missing (besides sleep)? Do I need to implement some kind of
interface in test?
Public Class test
Public Sub New(ByVal v As Integer)
Me.Value = v
End Sub
Public Value As Integer
End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As New ArrayList
x.Add(New test(0))
x.Add(New test(1))
cbo.DataSource = x
End Sub
-AJ