ToolStripComboBox.SelectedItem change does not propagate to binding source

Posted by Marius on Stack Overflow See other posts from Stack Overflow or by Marius
Published on 2010-04-28T12:00:39Z Indexed on 2010/04/28 12:03 UTC
Read the original article Hit count: 307

Filed under:
|
|

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. 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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about toolstripcombobox