问题
I am trying to use windows forms databinding to hook up a combobox to a ViewModel class.
var items = new BindingList<Person>();
comboBox.DataSource = items;
comboBox.DisplayMember = "Name";
All works ok except when I remove items from the list. For example if I remove the currently selected item (selected in the combobox) the selectedIndexChanged and SelectedValueChanged events of the combobox don't fire.
回答1:
Found an answer. I had to use a BindingSource as middleman
var bindingsSource = new BindingSource();
bindingsSource.DataSource = new BindingList<Person>();
comboBox1.DataSource = bindingsSource;
comboBox1.DisplayMember = "Name";
This way I do get value changed events and even more than one when I deleted something.
来源:https://stackoverflow.com/questions/7420273/databinding-bindinglist-to-combobox-and-removing-items