title: Trying to bind a combobox to an enum in C#
body: <p>I have a class that contains a property that is an enum:</p>
  
  <pre><code>public RaTypes RaBucket1Type { get; set; }
  </code></pre>
  
  <p>My enum is:</p>
  
  <pre><code>    public enum RaTypes
  {
      Red,
      Yellow
  }
  </code></pre>
  
  <p>I was able to bind a form's combobox data-source to the enum so that when I click on the drop-down, I see the enumerations:</p>
  
  <pre><code>cmbBucket1Type.DataSource = Enum.GetValues(typeof(RaTypes));
  </code></pre>
  
  <p>When I load the form, I would like to populate the combo-box with the existing value.  I have tried the following:</p>
  
  <pre><code>        cmbBucket1Type.DisplayMember = "TradeType";
          cmbBucket1Type.ValueMember = "TradeEnumID";
          cmbBucket1Type.SelectedValue = EditedAlgorithm.RaBucket1Type;
  </code></pre>
  
  <p>But this did not work. </p>
  
  <p>Also, I'm not sure I have implemented the ValueChanged event handler correctly either:</p>
  
  <pre><code>EditedAlgorithm.RaBucket1Type = (RaTypes)((ComboBox)sender).SelectedItem;
  </code></pre>
  
  <p>Can someone help me understand:</p>
  
  <ol>
  <li>How to set the combobox to current value, and</li>
  <li>How to handle the event handler so I can set the property to whatever was selected?</li>
  </ol>
  
  <p>Thanks
  -Ed</p>
  
  <p><strong>UPDATES</strong>
  I have tried </p>
  
  <pre><code>    cmbBucket1Type.SelectedIndex = cmbBucket1Type.FindString(EditedAlgorithm.RaBucket1Type.ToString());
  </code></pre>
  
  <p>and</p>
  
  <pre><code>    cmbBucket1Type.SelectedItem = EditedAlgorithm.RaBucket1Type;
  </code></pre>
  
  <p>Neither works.</p>