By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,571 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,571 IT Pros & Developers. It's quick & easy.

Combobox / Arraylist Confusion

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
----------------------
"Bruce D" <br*************@hotmail.com> wrote in message
news:11*************@corp.supernews.com...
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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.