This results in the binding of two bindings in the collection to the same property. Parameter name: binding error in C #?

I am trying to bind a datasource with LookupEdit at runtime. I tried this code but getting an error . This results in the binding of two bindings in the collection to the same property. Parameter Name: Binding Help me solve this problem? This 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 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 values.
coll.Add(new LookUpColumnInfo("CustomerName", 0));

Thanks in advance, Srihari

+4
source share
2 answers

Each control can have only one binding at a time. It looks like you already have text field bindings before and now, when you try to drag it, it throws an error. You need to clear the old binding before adding a new one.

, :

CBL_SelectCustomer.DataBindings.Clear();
CBL_SelectCustomer.DataBindings.Add("EditValue", binding_cust, "CustomerId");
+9

:

CBL_SelectCustomer.DataBindings.Clear();
+3

Source: https://habr.com/ru/post/1537630/


All Articles