2

我正在尝试使用 Windows 窗体数据绑定将组合框连接到 ViewModel 类。

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

一切正常,除非我从列表中删除项目。例如,如果我删除当前选定的项目(在组合框中选择),则组合框的 selectedIndexChanged 和 SelectedValueChanged 事件不会触发。

4

1 回答 1

4

找到了答案。我不得不使用 BindingSource 作为中间人

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

这样,当我删除某些内容时,我确实得到了价值改变事件,甚至不止一个。

于 2011-09-14T17:37:09.720 回答