I have ComboBox bound to BindingSource which in turn is bound to Linq Table.
我将ComboBox绑定到BindingSource,而BindingSource又绑定到Linq Table。
Also, ComboBox is filled from datasource which is a Linq Table.
此外,ComboBox是从数据源填充的,这是一个Linq表。
I want to assign new value to one of properties of BindingSource.Current whenever user selects item in ComboBox. I understood from MSDN that I need to use SelectionChangeCommitted event of ComboBox.
每当用户在ComboBox中选择项目时,我想为BindingSource.Current的一个属性赋值。我从MSDN了解到我需要使用ComboBox的SelectionChangeCommitted事件。
Here is pseudo code:
这是伪代码:
myCB_SelectionChangeCommitted(...)
{
var val = myCB.SelectedValue; //I get selected value from user.
var q = bindingSource.Current as XYZ;
//Ommitted validation code to check if q is okay to work with
q.SomeProperty = NewCalculatedValue; //SomeProperty is bound to label
//After above line, myCB.SelectedValue is lost!
//It seems that this event fires **before** selected value
//is written to bound data source
}
Do I have to use myCB.DataBindings[0].WriteValue(); ? Or is there a better way?
我是否必须使用myCB.DataBindings [0] .WriteValue(); ?或者,还有更好的方法?
Thanks in advance.
提前致谢。
1 个解决方案
#1
I would do something like
我会做点什么的
long index = q.databaseindex;
LinqObject = (from l in DataContext.linqtable where l.index = index select l).First();
//Make sure you do a check that count > 0 before calling First!
LinqObject.property = value;
LinqObject.SubmitChanges();
This way regardless of how the object is persisted to the ComboBox you'll be able to capture the object from the database and then update it with the value, etc.
这样,无论对象如何持久保存到ComboBox,您都可以从数据库中捕获对象,然后使用值等更新它。
Let us know
让我们知道
#1
I would do something like
我会做点什么的
long index = q.databaseindex;
LinqObject = (from l in DataContext.linqtable where l.index = index select l).First();
//Make sure you do a check that count > 0 before calling First!
LinqObject.property = value;
LinqObject.SubmitChanges();
This way regardless of how the object is persisted to the ComboBox you'll be able to capture the object from the database and then update it with the value, etc.
这样,无论对象如何持久保存到ComboBox,您都可以从数据库中捕获对象,然后使用值等更新它。
Let us know
让我们知道