0
我有ComboBox绑定到BindingSource然后绑定到Linq表。组合框和Linq到Winforms的
另外,ComboBox从Linq Table的数据源中填充。
无论何时用户在ComboBox中选择项目,我都希望为BindingSource.Current的某个属性分配新值。我从MSDN了解到我需要使用ComboBox的SelectionChangeCommitted事件。
这里是伪代码:
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
}
是否必须使用myCB.DataBindings [0] .WriteValue(); ?或者,还有更好的方法?
在此先感谢。