我試圖讓新的行寫入我們的數據庫時Winforms組合框自動刷新。用Winforms和EF 4.1進行數據綁定代碼優先
POCO EF類:
public class BaseSweep
{
public int BaseSweepId { get; set; }
//stuff removed for clarity
}
我通過這樣一個的BindingList綁定到數據:
public BindingList<BaseSweep> TopSweeps()
{
LocalDbContext.BaseSweep.Load();
return LocalDbContext.BaseSweep.Local.ToBindingList();
}
private void BindSweepList() //called in Form_Load
{
comboBoxSweepIds.DataSource = _dataAccess.TopSweeps();
comboBoxSweepIds.DisplayMember = "BaseSweepId";
comboBoxSweepIds.ValueMember = "BaseSweepId";
}
也能正常工作的初始綁定,顯示當前的ID在該表。隨着新行添加到表中,LocalDbContext.BaseSweep.Local
中的計數會按預期增加。但是,comboBoxSweepIds
永遠不會更新。任何想法我做錯了什麼?