title: Setting an enum bound combobox selected value to an enum value
body: <p>There is an enum in my project like this:</p>
  
  <pre><code>public enum UserFrienlyEnum
  {
      [Description("it need spec training")]
      SPECIAL_TRAINING = 1,
      [Description("it need normal training")]
      NORMAL_TRAINING = 2,
      [Description("it need simple training")]
      SIMPLE_TRAINING = 3
  }
  </code></pre>
  
  <p>I bound this enum to a combobox by using this method:</p>
  
  <pre><code>public static void setEnumValues(ComboBox cxbx, Type typ)
  {
      if (!typ.IsEnum)
      {
          throw new ArgumentException("Only Enum types can be set");
      }
  
      List&lt;KeyValuePair&lt;string, int&gt;&gt; list = new List&lt;KeyValuePair&lt;string, int&gt;&gt;();
  
      foreach (int i in Enum.GetValues(typ))
      {
          string name = Enum.GetName(typ, i);
          string desc = name;
          FieldInfo fi = typ.GetField(name);
  
          // Get description for enum element
          DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
  
          if (attributes.Length &gt; 0)
          {
              string s = attributes[0].Description;
  
              if (!string.IsNullOrEmpty(s))
              {
                  desc = s;
              }
          }
  
          list.Add(new KeyValuePair&lt;string, int&gt;(desc, i));
      }
      // NOTE: It is very important that DisplayMember and ValueMember are set before DataSource.
      //       If you do, this works fine, and the SelectedValue of the ComboBox will be an int
      //       version of the Enum.
      //       If you don't, it will be a KeyValuePair.
      cxbx.DisplayMember = "Key";
      cxbx.ValueMember = "Value";
      cxbx.DataSource = list;
  }
  </code></pre>
  
  <p>And use above method for binding combobox to myEnum in this way:</p>
  
  <pre><code>setEnumValues(comboBox, typeof(myEnum));
  </code></pre>
  
  <p>Now question is how I can set my combobox item or value to a specific one, something like this:</p>
  
  <pre><code>combobox.SelectedValue = myEnum.value;
  </code></pre>
  
  <p>My project is a C# windows project in Visual Studio 2010 environment.</p>