【发布时间】:2014-06-07 19:33:50
【问题描述】:
我尝试在运行时将数据源绑定到DevExpress.XtraEditors.LookupEdit。我尝试了此代码,但收到以下错误:
这会导致集合中的两个绑定绑定到同一个属性。参数名称:绑定。
这是我的代码:
// 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));
如何解决这个错误?
【问题讨论】:
-
您在哪一行得到异常?
-
我在代码中提到的第 6 行
CBL_SelectCustomer.DataBindings.Add("EditValue", binding_cust, "CustomerId");
标签: c# winforms devexpress