LookUpEdit绑定到两个BindingSources时不起作用

时间:2014-02-10 08:55:56

标签: c# winforms devexpress bindingsource

我遇到一个问题,LookUpEdit的值未在DataBindings添加的DataSource中更新。我所做的是我对表单进行LookUpEdit控制并设置了LookUpEdit DataSource,Value和DisplayMember。然后我添加了DataBindings第二个BindingSource,其中LookUpEdit中的更改值未在第二个BindingSource中更新:

BindingSource bindingSource1 = // here i get IQueryable 
BindingSource bindingSource2 = // here i get IQueryable where one field from bindingSource1 is set as foreign key

lookUpEdit1.Properties.DataSource = bindingSource1.
lookUpEdit1.Properties.ValueMember = "Id";
lookUpEdit1.Properties.DisplayMember = "Name";

lookUpEdit1.DataBindings.Add("EditValue", bindingSource2, "fk_id", true,     DataSourceUpdateMode.OnPropertyChanged);

有时候我会System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException was unhandled too。第二个BindingSource设置为GridControl的DataSource,即GridView。

1 个答案:

答案 0 :(得分:0)

设置gridView1.OptionsBehavior.CacheValuesOnRowUpdating = CacheRowValuesMode.Disabled。