【问题标题】:Databinding bindinglist to combobox and removing items将绑定列表数据绑定到组合框并删除项目
【发布时间】:2011-11-17 05:30:00
【问题描述】:

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

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

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

【问题讨论】:

    标签: winforms data-binding combobox bindinglist


    【解决方案1】:

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

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

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

    【讨论】:

    • 这是否被视为 Microsoft 错误?有没有官方的说法?
    猜你喜欢
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 2014-03-16
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多