I do it this way, but maybe there is a better way:
List<ListItem<MyEnum>> enumVals = new List<ListItem<MyEnum>>();
foreach( MyEnum m in Enum.GetValues (typeof(MyEnum) )
{
enumVals.Add (new ListItem<MyEnum>(m, m.ToString());
}
myComboBox.DataSource = enumVals;
myComboBox.ValueMember = "Key";
myComboBox.DisplayMember = "Description";
Note that ListItem<T>this is a custom class I created that contains the Key property and the Description property.
, :
- , SelectedValue combobox
- , , , INotifyPropertyChanged, combobox.
myComboBox.DataBindings.Add ("SelectedValue", theBindingSource, "YourPropertyName");
public class TheClass : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private MyEnum _myField;
public MyEnum MyPropertyName
{
get { return _myField; }
set
{
if( _myField != value )
{
_myField = value;
if( PropertyChanged != null )
PropertyChanged ("MyPropertyName");
}
}
}
}