473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Combobox / Arraylist Confusion

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
1 2936
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CalPARK InterNetStation | last post by:
Could anyone explain why the difference of behavior betweein Case1 and Case2 occurs? Microsoft Visual C#.NET 55607-652-0000007-18218 Windows Forms Application 1. put a TabControl on a Form...
1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
3
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method...
4
by: Peter | last post by:
C# .NET 1.1 How do I sort ComboBox in descending order? Thanks Peter
4
by: Paul Cheetham | last post by:
Hi, I have a combo box in a Windows Forms app (c# VS2003, .Net 1.1) where I am adding items at runtime using the Items.Add method. I need to be able to also set the Value for each item in the...
1
by: MrNobody | last post by:
I have a ComboBox on my form, and I set it's DataSource to an ArrayList of custom objects. Everything loads fine, all the entries I initially loaded into the ArrayList appear in my ComboBox. ...
4
by: polaris431 | last post by:
All the examples I've seen showing how to populate a combobox using the DataSource property and an ArrayList show the ArrayList object containing objects with at least two properties. I want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.