【发布时间】:2010-10-21 20:23:58
【问题描述】:
我将 ComboBox 绑定到 BindingSource,而后者又绑定到 Linq Table。
此外,ComboBox 是从作为 Linq 表的数据源填充的。
每当用户选择 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(); ?还是有更好的办法?
提前致谢。
【问题讨论】:
标签: .net winforms linq-to-sql data-binding combobox