I have an enum, example:
enum MyEnum
{
My_Value_1,
My_Value_2
}
With :
comboBox1.DataSource = Enum.GetValues(typeof(MyEnum)
If you're using .NET 3.5, you could add this extension class:
public static class EnumExtensions {
public static List GetFriendlyNames(this Enum enm) {
List result = new List();
result.AddRange(Enum.GetNames(enm.GetType()).Select(s => s.ToFriendlyName()));
return result;
}
public static string GetFriendlyName(this Enum enm) {
return Enum.GetName(enm.GetType(), enm).ToFriendlyName();
}
private static string ToFriendlyName(this string orig) {
return orig.Replace("_", " ");
}
}
And then to set up your combo box you'd just do:
MyEnum val = MyEnum.My_Value_1;
comboBox1.DataSource = val.GetFriendlyNames();
comboBox1.SelectedItem = val.GetFriendlyName();
This should work with any Enum. You'd have to make sure you have a using statement for the namespace that includes the EnumExtensions class.