Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  153 Posts | 0 Stories | 2415 Comments | 653 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

Wednesday, April 07, 2010 #

This is quite simple...

Define the enum eg:

public enum MyEnum{
  ItemOne,
  ItemTwo,
}

Within the form set the datasource of the combobox to the values of the enum eg:

myCombo.DataSource = System.Enum.GetValues(typeof(MyEnum));

To have the combo auto select a value based on a bound object, set the databinding of the combo eg:

class MyObject{
  private MyEnum myEnumProperty;
  public MyEnum MyEnumProperty{get {return myEnumProperty;}}
}
MyObject myObj = new MyObject();
myCombo.DataBindings.Add(new Binding("SelectedIndex", myObject, "MyEnumProperty");