我仍然在WPF,EF和MVVM的學習階段,現在我得到了以下Probplem。我可以在我的DataGridView中刪除和插入新項目,但我不知道如何更新我的項目。我所做的只是選擇一個已經獲得主鍵的空行,然後將數據放入其中。它正在工作(更新數據庫),但GridView不刷新。我需要先重新啓動程序才能看到我的更新數據。EF更新不更新GridView
我的執行命令來更新我的數據庫。我在ViewModel類
public void ExecuteUpdate(object obj)
{
try
{
SelectedIndex.Child_Update(new Farbe { FarbauswahlNr = SelectedIndex.FarbauswahlNr, Kurztext = SelectedIndex.Kurztext, Ressource = SelectedIndex.Ressource, Vari1 = SelectedIndex.Vari1, Vari2 = SelectedIndex.Vari2 });
//ListeAktualisieren --> Refreshing the List
ListeAktualisieren();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
這是我的Regresh方法至少應該刷新GridView。林在ViewModel類
public void ListeAktualisieren()
{
farbliste.ListeAktualisieren(db);
farbliste.Model = farbliste.Model.Concat(farbliste.Addlist).ToList();
Model = farbliste.Model;
farbliste.Addlist.Clear();
}
該方法被調用我的企業名單至極也得到了Refreh方法。在這裏從我的數據庫讀取。 IM在商戶列表類
public void ListeAktualisieren(TestDBEntities db)
{
Model.Clear();
foreach (var item in db.Farben)
{
//Insert and delete working
add = new Farbe { FarbauswahlNr = item.FarbauswahlNr, Kurztext = item.Kurztext, Ressource = item.Ressource, Vari1 = Convert.ToBoolean(item.Var1), Vari2 = item.Vari2 };
Addlist.Add(add);
}
}
型號是我的GridView至極的來源是不是清爽更新,但插入或刪除時,顯示新的數據行時更改的數據。
我的物業有一個OnPropertyChange。 – 2013-03-20 13:45:00
PropertyChangedEvent必須到達WPF層你的連接從ViewModel到WPF如何? – Patrick 2013-03-20 13:54:01
Farbliste.cs和Farbe.cs是CSLA classen所以我不認爲有一個Observablecollection需要? – 2013-03-20 14:09:00