开发者

ToolStripComboBox.SelectedItem change does not propagate to binding source

开发者 https://www.devze.com 2022-12-28 05:57 出处:网络
My binding is set up as this: _selectXAxisUnitViewModelBindingSource = new BindingSource(); _selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);

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;
        _selectedU开发者_Go百科nitComboBox.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. 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. If I add the ToolStripItem directly to the MenuStrip everything works fine. 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.


Can you change

 _selectXAxisUnitViewModelBindingSource.DataSource = typeof(SelectXAxisUnitViewModel);

To

 _selectXAxisUnitViewModelBindingSource.DataSource = new SelectXAxisUnitViewModel();
0

精彩评论

暂无评论...
验证码 换一张
取 消