title: How to bind Enum to ComboBox in a DataGrid
body: <p>I found this on Stack Overflow, but no where I could get an answer.</p>
  
  <p>I want to bind a ComboBox of a data grid to a <code>property of a class</code> which returns [one of the ] Enum Value.</p>
  
  <pre><code>MyEnum
  {
      [StringValue("SomeVal")]
      SomeVal,
      [StringValue("AnotherVal")]
      AnotherVal,
      [StringValue("OneMoreVal")]
      OneMoreVal
  }
  
  class MyClass
  {
      public MyEnum A_Value
      {
          return whatever; // whatever is MyEnum type
      }
  }
  </code></pre>
  
  <p>Now I made a Data grid column having combo box and there I need to bind a property</p>
  
  <pre><code>myCombo.DataSource = Enum.GetValues(typeof(MyEnum)); 
  myCombo.DataBindings.Add("SelectedValue", myDataSource, bindingPath + ".A_Value");
  </code></pre>
  
  <p>When I run this code, it fails with error</p>
  
  <blockquote>
    <p>"Cannot set a value to a combo box without a ValueMember"</p>
  </blockquote>
  
  <p>Then I add below line</p>
  
  <pre><code>myCombo.ValueMember = "Value";
  </code></pre>
  
  <p>It does not fail this time, but no selected value is set.
  <strong>Can someone help me out with the problem ?</strong></p>
  
  <hr>
  
  <p>What I referred:</p>
  
  <ul>
  <li><a href="http://www.c-sharpcorner.com/uploadfile/mahesh/binding-an-enum-to-a-combobox/" rel="nofollow noreferrer">http://www.c-sharpcorner.com/uploadfile/mahesh/binding-an-enum-to-a-combobox/</a></li>
  <li><a href="https://stackoverflow.com/questions/906899/binding-an-enum-to-a-winforms-combo-box-and-then-setting-it">Binding an enum to a WinForms combo box, and then setting it</a></li>
  <li><a href="https://stackoverflow.com/questions/5638639/how-to-bind-an-enumeration-to-combobox">How to bind an enumeration to combobox</a></li>
  <li><a href="https://stackoverflow.com/questions/15040872/adding-enum-values-to-a-simple-combobox">adding enum values to a simple combobox</a></li>
  </ul>