JG Vimalan's Blog

It is all about coding!

Cannot bind to the new display member. Parameter name: newDisplayMember

I got this error when I was trying to bind datasource in a combobox and set values in the ‘DisplayMember’ and ‘ValueMember’.

Here is the code snippet,

public class ClinicInfo
{
internal string ClinicID { get; set; }
internal string ClinicName { get; set; }

public override string ToString()
{
return ClinicName;
}
}

//Code for binding the data into ComboBox

IEnumerable<ClinicInfo> clinics = DBGateway.GetActiveClinics();

ClinicCmbBox.DataSource = clinics;
ClinicCmbBox.ValueMember = “ClinicID”;
ClinicCmbBox.DisplayMember = “ClinicName”;

Everything was looking good except the Access Modifiers (internal) for the properties in ClinicInfo class.

When I changed that to public as shown below, everything worked fine.

public string ClinicID { get; set; }
public string ClinicName { get; set; }

So, the properties you are setting in ‘ValueMember’ and ‘DisplayMember’ should be public.

About these ads

September 27, 2011 - Posted by | C#.NET, Windows Forms

2 Comments »

  1. Thank you, this puzzled me quite a bit before finding your post.

    Comment by Quang | January 26, 2012 | Reply

  2. you should use this cod
    ClinicCmbBox.DataSource = clinics.table[0];

    Comment by sarviiin | August 6, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: