473,395 Members | 1,516 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,395 software developers and data experts.

Another ComboBox data source gotcha

Here's another one. The code is below.

If I display to the ListBox, I get the exception:

Could not bind to the new display member, Parameter name:
newDisplayMember

and all ListBox members are set to MtProg.Form1.USState

If I comment out the listBox1 lines, leaving the comboBox1 lines, I get the
same exception but the combo box remains unchanged.
public class USState
{
public string longName;
public string shortName;
public USState(string shortName, string longName)
{
this.shortName=shortName;
this.longName=longName;
}
}

ArrayList USStates = new ArrayList();

private void button1_Click(object sender, System.EventArgs e)
{
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI"));
USStates.Add(new USState("Wyoming", "WY"));

listBox1.DataSource = USStates;
listBox1.DisplayMember = "longName";
listBox1.ValueMember = "shortName";

comboBox1.DataSource = USStates;
comboBox1.DisplayMember = "longName";
comboBox1.ValueMember = "shortName";
}
Nov 17 '05 #1
3 4227
OK, I made some progreess. If I remove the ValueMember lines, the exception
goes away.

However, both controls contain the values:

"ComboBoxArrayBind.Form1+USState"

Can anyone see what I am missing?

Thanx,
Bill

Nov 17 '05 #2
It works for a one-D ArrayList

public ArrayList stData = new ArrayList();

private void Form1_Load(object sender, System.EventArgs e)

{

stData.Add("AAA");

stData.Add("BBB");

stData.Add("CCC");

stData.Add("DDD");

try

{

listBox1.DataSource = stData;

comboBox1.DataSource = stData;

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}

Nov 17 '05 #3
Got it. Had to access via properties.

public ArrayList USStates = new ArrayList();
public class USState
{
public string longName;
public string shortName;
public USState(string longName, string shortName)
{
this.shortName=shortName;
this.longName=longName;
}
public string LongName
{
get
{
return longName;
}
}
public string ShortName
{
get
{
return shortName;
}
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI"));
USStates.Add(new USState("Wyoming", "WY"));
USStates.Add(new USState("New Jersey", "NJ"));
try
{
listBox1.DataSource = null;
listBox1.DataSource = USStates;
listBox1.DisplayMember = "LongName";
comboBox1.DataSource = null;
comboBox1.DataSource = USStates;
comboBox1.DisplayMember = "LongName";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: scottallenmccullough | last post by:
I'm sure there is an easy solution for this problem. On "FORM A" is a combobox with a separate table as its record source. If the data required in the combobox is not one of the available choices...
3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
3
by: PeterZ | last post by:
G'day, After doing much searching and pinching bits of ideas from here there and everywhere I came up with a fairly 'clean' solution of including a comboBox into a dataGrid column. You can...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
12
by: Art | last post by:
Hi, I've got a number of ListBoxes that hold data from an Access database. On another tab of my form I need the user to use a ComboBox to choose one of the items from one of the ListBoxes. I...
11
by: DSR | last post by:
Help Please... I would like to populate a combo box on a form with a query that compares data from two tables. Any record that is unique in table1 should continue to populate my combobox. The...
1
by: fiaolle | last post by:
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this...
19
by: active | last post by:
I'm using a ComboBox to display objects of a class I've defined, say CQQ. Works great except somehow I occasionally set an Item to a String object instead of an object of type CQQ. It looks...
2
by: Dorish3 | last post by:
I want to apologize ahead of time for being a novice with MS Access and VBA. I desperately need help with 2 queries that I am trying to put together. I want to thank anyone that can help me out...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.