exception: "Could not bind to the new value member"

  • Thread starter Thread starter Dmitry Sazonov
  • Start date Start date
D

Dmitry Sazonov

I'm trying to bing ComboBox and getting error:
"An unhandled exception of type 'System.ArgumentException' occurred in
system.dll

Additional information: Could not bind to the new value member."

here is code:
//
// class type definition
//
public class CustomerType
{
private int myId;
private string myName;

public CustomerType(int Id, string Name )
{
this.myId = Id;
this.myName = Name;
}

public int Id
{
get
{
return this.myId;
}
}

public string Name
{
get
{
return this.myName;
}
}

public override string ToString()
{
return this.myId + " - " + this.myName;
}
}

//
// MyForm.OnLoad member
//

// create and fill Array
ArrayList CustomerTypes = new ArrayList();
CustomerTypes.Add(new CustomerType(1, "aaa"));
CustomerTypes.Add(new CustomerType(2, "bbb"));
CustomerTypes.Add(new CustomerType(3, "ccc"));

// set it as Data Source for combo box
comboBox.DataSource = CustomerTypes;
comboBox.DisplayMember = "Name";
comboBox.ValueMember = "Id";

// attempt to bind "ValueMember" - exeption is here
comboBox.DataBindings.Add("ValueMember", customer, "CustomerTypeID");


//Note: Object customer have "int" property named "CustomerTypeID" and
should bind fine
// for example, next code works great and does not raise exeption:
comboBox.DataBindings.Add("SelectedIndex", customer, "CustomerTypeID");

Can somebody help me here? Thank you in advance.
 
sorry for call: I fixed it:

comboBox.DataBindings.Add("SelectedValue", customer, "CustomerTypeID");
 
Back
Top