2011-09-14 34 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

这是否被认为是微软的错误?有没有官方的文章呢? –