I have tried to bind a datasource to a DevExpress.XtraEditors.LookupEdit
at run-time. I tried this code, but am getting the following error:
This causes two bindings in the collection to bind to the same property. Parameter name: binding.
Here is my code:
// Create an adapter to load data from the "Customers" table.
OleDbDataAdapter testcustomers = new OleDbDataAdapter(
"SELECT CustomerId, Customername FROM Customer WHERE CompanyId =" + TXE_CompId.Text, connection);
DataSet ds = new DataSet(); // Create a dataset that will provide data from the database.
testcustomers.Fill(ds, "Customer"); // Load data from the "Customers" table to the dataset.
// A BindingSource for the "Customers" table.
BindingSource binding_cust = new BindingSource(ds, "Customer");
CBL_SelectCustomer.DataBindings.Add("EditValue", binding_cust, "CustomerId"); // getting error on this line
// Specify the data source to display in the dropdown.
CBL_SelectCustomer.Properties.DataSource = binding_cust;
// The field providing the editor's display text.
CBL_SelectCustomer.Properties.DisplayMember = "CustomerName";
// The field matching the edit value.
CBL_SelectCustomer.Properties.ValueMember = "CustomerId";
// Add two columns to the dropdown.
LookUpColumnInfoCollection coll = CBL_SelectCustomer.Properties.Columns;
// A column to display the ProductID field's values.
coll.Add(new LookUpColumnInfo("CustomerName", 0));
How can this error be fixed?
Clear binding first and then add it to the control:
Try this before binding: