【发布时间】:2012-12-18 15:17:17
【问题描述】:
我似乎无法弄清楚这一点,也找不到任何答案。
我有一个组合框绑定到我的模型中的一个属性。 我将在我的代码中复制并粘贴关键行:
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 组合框几乎相同。
我该如何解决这个问题?
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# user-interface devexpress