2011-09-14 174 views
2

我正在嘗試使用Windows窗體數據綁定將組合框連接到ViewModel類。將綁定列表綁定到組合框並刪除項目

var items = new BindingList<Person>(); 
comboBox.DataSource = items; 
comboBox.DisplayMember = "Name"; 

除了當我從列表中刪除項目時,所有工作都正常。例如,如果我刪除當前選定的項目(在組合框中選擇),組合框的selectedIndexChanged和SelectedValueChanged事件不會觸發。

回答

4

找到了答案。我不得不使用的BindingSource作爲中間人

var bindingsSource = new BindingSource(); 
    bindingsSource.DataSource = new BindingList<Person>(); 
    comboBox1.DataSource = bindingsSource; 
    comboBox1.DisplayMember = "Name"; 

這樣,我得到的值變化事件,甚至不止一個,當我刪除的東西。

+1

這是否被認爲是微軟的錯誤?有沒有官方的文章呢? –

相關問題