Combobox / Arraylist Confusion

B

Bruce D

I'm confused on the best way to create a combobox with "YES"/"NO" and values
of "Y""/N". I'm trying this way...but I get an error: Could not bind to the
new display member

Public Class combo
Inherits System.Windows.Forms.Form
Public Structure sItems
Public DisplayVal As String
Public RealVal As String
End Structure

Dim arlist As ArrayList
Dim sList As sItems

Private Sub combo_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
arlist = New ArrayList
sList = New sItems

sList.DisplayVal = "Yes"
sList.RealVal = "Y"
arlist.Add(sList)

sList.DisplayVal = "No"
sList.RealVal = "N"
arlist.Add(sList)

Me.ComboBox1.DataSource = arlist
Me.ComboBox1.DisplayMember = "DisplayVal"
Me.ComboBox1.ValueMember = "RealVal"
End Sub
End Class


Any help is appreciated!

-BD
 
K

Ken Tucker [MVP]

Hi,

Replace the structure with a class with properties. You can
only bind to properties in a class.


Public Class sItems
Dim mstrVal As String
Dim mstrReal As String

Public Property DisplayVal() As String
Get
Return mstrVal
End Get
Set(ByVal Value As String)
mstrVal = Value
End Set
End Property

Public Property RealVal() As String
Get
Return mstrReal
End Get
Set(ByVal Value As String)
mstrReal = Value
End Set
End Property
End Class

Ken
----------------------
I'm confused on the best way to create a combobox with "YES"/"NO" and values
of "Y""/N". I'm trying this way...but I get an error: Could not bind to the
new display member

Public Class combo
Inherits System.Windows.Forms.Form
Public Structure sItems
Public DisplayVal As String
Public RealVal As String
End Structure

Dim arlist As ArrayList
Dim sList As sItems

Private Sub combo_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
arlist = New ArrayList
sList = New sItems

sList.DisplayVal = "Yes"
sList.RealVal = "Y"
arlist.Add(sList)

sList.DisplayVal = "No"
sList.RealVal = "N"
arlist.Add(sList)

Me.ComboBox1.DataSource = arlist
Me.ComboBox1.DisplayMember = "DisplayVal"
Me.ComboBox1.ValueMember = "RealVal"
End Sub
End Class


Any help is appreciated!

-BD
 

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