我似乎無法弄清楚這一點,並找不到任何答案。強制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/)」,其中的共識是「不,他們不應該」。 –