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(); ?或者,還有更好的方法?
在此先感謝。