这会导致集合中的两个绑定绑定到同一个属性。参数名称:c#中的绑定错误 [英] This causes two bindings in the collection to bind to the same property. Parameter name: binding error in c#?

查看:478
本文介绍了这会导致集合中的两个绑定绑定到同一个属性。参数名称:c#中的绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在运行时将数据源绑定到LookupEdit我尝试过该代码,但是收到错误这会导致集合中的两个绑定绑定到同一个属性。
参数名称:绑定
帮我解决这个问题?这是我的代码

I try to bind datasource to LookupEdit in runtime I tried this code but getting error This causes two bindings in the collection to bind to the same property. Parameter name: binding Help me to solve this ? 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'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));

提前感谢
Srihari

Thanks in advance, Srihari

推荐答案


每个控件一次只能有一个绑定。它看起来像你
已经绑定到文本框之前和现在当你尝试
重新绑定它,它会抛出一个错误。您需要在添加新的绑定
之前清除旧的绑定

Every Control can have only one binding at a time. It looks like you already have a binding to the textboxes before and now when you try to rebind it, it throws an error. You need to clear the old binding before adding a new one.

首先清除绑定,然后将其添加到控件:

Clear binding first and then add it to the control:

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

这篇关于这会导致集合中的两个绑定绑定到同一个属性。参数名称:c#中的绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆