[英]ToolStripComboBox.SelectedItem change does not propagate to binding source
My binding is set up as this: 我的绑定设置如下:
_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;
The property "AvailableUnits" is a collection of strings and the "SelectedUnit" is a string-property. 属性“ AvailableUnits”是字符串的集合,而“ SelectedUnit”是字符串属性。 Now the dropdown list is populated as expected, but when I select and item in the list, the change is not propagated to the binding source.
现在,按预期填充了下拉列表,但是当我选择列表中的项目时,更改不会传播到绑定源。 Any idea what I am doing wrong?
知道我在做什么错吗?
Update: 更新:
I Created a little test project and this problem occurs when I add a ToolStripComboBox as a subitem of another ToolStripItem. 我创建了一个小测试项目,当我将ToolStripComboBox添加为另一个ToolStripItem的子项时,会出现此问题。 If I add the ToolStripItem directly to the MenuStrip everything works fine.
如果我将ToolStripItem直接添加到MenuStrip,则一切正常。 The BindingContext is not assigned to the ToolStripComboBox when added as a sub item (see my code-comment) and my fix doesn't seem to do whats necessary to get this to work.
当作为子项添加时,BindingContext没有分配给ToolStripComboBox(请参阅我的代码注释),并且我的修补程序似乎没有做任何必要的工作才能使此工作。
Can you change 你能改变吗
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);
To 至
_selectXAxisUnitViewModelBindingSource.DataSource = new SelectXAxisUnitViewModel();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.