toolstripcombobox.selectedItem更改不会传播到绑定源
-
02-10-2019 - |
题
我的绑定是这样的:
_selectXAxisUnitViewModelBindingSource = new BindingSource();
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);
_selectedUnitComboBoxBindingSource = new BindingSource();
_selectedUnitComboBoxBindingSource.DataSource = _selectXAxisUnitViewModelBindingSource;
_selectedUnitComboBoxBindingSource.DataMember = "AvailableUnits";
_selectedUnitComboBox.ComboBox.DataSource = _selectedUnitComboBoxBindingSource;
_selectedUnitComboBox.ComboBox.DisplayMember = String.Empty;
_selectedUnitComboBox.ComboBox.ValueMember = String.Empty;
_selectedUnitComboBox.ComboBox.DataBindings.Add("SelectedItem",
_selectXAxisUnitViewModelBindingSource,
"SelectedUnit", true, DataSourceUpdateMode.OnPropertyChanged);
// this is a bug in the .Net framework: http://connect.microsoft.com/VisualStudio/feedback/details/473777/toolstripcombobox-nested-on-toolstripdropdownbutton-not-getting-bindingcontext
_selectedUnitComboBox.ComboBox.BindingContext = this.BindingContext;
属性“可用nits”是字符串的集合,“ selectedunit”是字符串范围。现在,下拉列表按预期填充,但是当我在列表中选择和项目时,更改不会传播到绑定源。知道我做错了什么?
更新:
我创建了一个小测试项目,当我添加一个工具combobox作为另一个工具条的子信息时,就会发生这个问题。如果我将工具条直接添加到menustrip中,一切正常。当添加为子项目时,bindingContext并未分配给工具combobox(请参阅我的代码评估),而我的修复程序似乎并没有做任何必要的事情来使其工作。
没有正确的解决方案
其他提示
你能改变吗?
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);
到
_selectXAxisUnitViewModelBindingSource.DataSource = new SelectXAxisUnitViewModel();
不隶属于 StackOverflow