我的绑定设置如下:
_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;属性"AvailableUnits“是一个字符串集合,"SelectedUnit”是一个字符串属性。现在,下拉列表已按预期填充,但当我选择列表中的and item时,更改不会传播到绑定源。你知道我做错了什么吗?
更新:
我创建了一个小测试项目,当我添加一个ToolStripComboBox作为另一个ToolStripItem的子项时,就会出现这个问题。如果我将ToolStripItem直接添加到MenuStrip中,则一切正常。当作为子项添加时,BindingContext不会分配给ToolStripComboBox (请参阅我的代码注释),而且我的修复似乎没有完成让它工作所必需的事情。
发布于 2010-04-28 20:44:55
你能改变吗?
_selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);至
_selectXAxisUnitViewModelBindingSource.DataSource = new SelectXAxisUnitViewModel();https://stackoverflow.com/questions/2729175
复制相似问题