title: Why does the ComboBox.SelectedValue DataBinding context gets cleared when BindingList changes?
body: <p>I have some logic in the business layer that limits the ComboBox options according to inputs, so I need to change the values in the underlying BindingList. But when the list gets changed, the two-way binding becomes one-way from UI to Entity only.</p>
  
  <pre><code>_mComboBox.DataBindings.Add("SelectedValue", _mEntity, "WifeCount");
  </code></pre>
  
  <p>Full code with problem in the assign button click handler:</p>
  
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace EnumDataBinding
  {
      public partial class Form1 : Form
      {
          ComboBox _mComboBox = new ComboBox();
          Button _mCheckButton = new Button();
          Button _mAssignButton = new Button();
  
          BindingList&lt;OptionValue&gt; _mBindingList = new BindingList&lt;OptionValue&gt;();
          List&lt;OptionValue&gt; _mCacheList = new List&lt;OptionValue&gt;();
  
          Entity _mEntity = new Entity();
  
          public Form1()
          {
              InitializeComponent();
  
              // create a reset button
              _mCheckButton.Size = new Size(100, 30);
              _mCheckButton.Text = "Check";
              _mCheckButton.Location = new Point(100, 100);
              _mCheckButton.Click += new EventHandler(_mCheck_Click);
  
              // create assignment button
              _mAssignButton.Size = new Size(100, 30);
              _mAssignButton.Text = "Assign";
              _mAssignButton.Location = new Point(100, 135);
              _mAssignButton.Click += new EventHandler(_mAssignButton_Click);
  
              // create a combo box
              _mComboBox = new ComboBox();
              _mComboBox.Size = new System.Drawing.Size(300, 30);
              _mComboBox.Location = new Point(100, 200);
  
              this.Controls.AddRange(new Control[] {
                  _mComboBox,
                  _mCheckButton,
                  _mAssignButton
              });
  
              // fill the bindinglist
              _mBindingList.Add(new OptionValue("One", 1M));
              _mBindingList.Add(new OptionValue("Two", 2M));
              _mBindingList.Add(new OptionValue("Three", 3M));
  
              _mCacheList.Add(new OptionValue("One", 1M));
              _mCacheList.Add(new OptionValue("Two", 2M));
              _mCacheList.Add(new OptionValue("Three", 3M));
          }
  
          void _mAssignButton_Click(object sender, EventArgs e)
          {
              // reset options
              _mBindingList.Clear();
              foreach (var o in _mCacheList)
                  _mBindingList.Add(o);
  
              // EXPECTED: Update ComboBox.SelectedValue and ComboBox.Text
              // RESULT: Does not happen.
              _mEntity.WifeCount = 3M;
  
              this.Text = string.Format("SelectedValue: {0}; WifeCount: {1}", _mComboBox.SelectedValue, _mEntity.WifeCount);
          }
  
          private void PrepareComboBox(ComboBox combobox, BindingList&lt;OptionValue&gt; list)
          {
              combobox.DropDownStyle = ComboBoxStyle.DropDown;
              combobox.AutoCompleteSource = AutoCompleteSource.ListItems;
              combobox.AutoCompleteMode = AutoCompleteMode.Suggest;
              combobox.DataSource = new BindingSource() { DataSource = list };
              combobox.DisplayMember = "Display";
              combobox.ValueMember = "Value";
              combobox.Text = string.Empty;
              combobox.SelectedText = string.Empty;
          }
  
          protected override void OnLoad(EventArgs e)
          {
              // combo box datasource binding
              PrepareComboBox(_mComboBox, _mBindingList);
  
              // entity data binding
              _mComboBox.DataBindings.Add("SelectedValue", _mEntity, "WifeCount", false);
  
              base.OnLoad(e);
          }
  
          void _mCheck_Click(object sender, EventArgs e)
          {
              this.Text = string.Format("SelectedValue: {0}; WifeCount: {1}", _mComboBox.SelectedValue, _mEntity.WifeCount);
          }
      }
  
      public class Entity : INotifyPropertyChanged
      {
          decimal _mWifeCount;
  
          public decimal WifeCount { get { return _mWifeCount; } set { _mWifeCount = value; OnPropertyChanged("WifeCount"); } }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected virtual void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      public class OptionValue
      {
          string _mDisplay;
          object _mValue;
  
          public string Display { get { return _mDisplay; } set { _mDisplay = value; } }
  
          public object Value { get { return _mValue; } set { _mValue = value; } }
  
          public OptionValue(string display, object value)
          {
              _mDisplay = display;
              _mValue = value;
          }
      }
  }
  </code></pre>
  
  <p>Update: Adding an event handler to the ComboBox seems to work:</p>
  
  <pre><code>void _mComboBox_SelectedValueChanged(object sender, EventArgs e)
  {
        var binding = (sender as Control).DataBindings["SelectedValue"];
        if (binding != null)
            binding.WriteValue();
  
        this.Text = string.Format("SelectedValue: {0}; WifeCount: {1}", _mComboBox.SelectedValue, _mEntity.WifeCount);
  }
  </code></pre>