我似乎无法弄清楚这一点,并找不到任何答案。强制BindingSource更新数据/型号
我有一个Combobox绑定到我的模型中的属性。 我只是复制并粘贴在我的代码键行:
this.m_typeCombobox.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.m_bindingSource, "Type", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
我的模型:
public class TypeConfig : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private EnumType<eLType> m_type;
public EnumType<eLType> Type
{
get { return m_type; }
set
{
if (m_type!= value)
{
m_type= value;
var handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs("Type"));
}
}
}
我需要有更新的组合框EditValueChanged事件的模型,但它看起来像模型更新后来。 EditValueChanged是更改时最新调用的事件。
我已经试过这样:
void m_TypeCombobox_EditValueChanged(object sender, EventArgs e)
{
m_bindingSource.EndEdit(); //this doesn't work
//need to have the new value here
}
这里的MSDN说什么:
当EndEdit中的方法被调用时,所有待处理的更改应用到底层数据源。 除非数据源包含的对象实现IEditableObject接口,否则此方法无效。如果对象没有实现IEditableObject接口,则在每次更改后立即将对数据的更改复制到基础数据源。
因此,从我的非公开模型中更改组合框值时应立即更新模型。
我使用的DevExpress组合框几乎与普通的WinForms组合框相同。
我该如何解决这个问题?
我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –