I've got a helper class to convert an enum into a list.
class EnumHelper
{
public static List<T> EnumToList<T>()
{
Type enumType = typeof(T);
// Can't use type constraints on value types, so have to do check like this
if (enumType.BaseType != typeof(Enum))
{
throw new ArgumentException("T must be of type System.Enum");
}
return new List<T>(Enum.GetValues(enumType) as IEnumerable<T>);
}
}
I can create a list using the ActorType enum.
List<ActorType> listActorType = EnumHelper.EnumToList<ActorType>();
for (int i = 0; i < listActorType.Count; ++i)
{
comboBox_Type.Items.Add(listActorType[i]);
}
I would like to select an enum based on the index of the list, is this possible?
comboBox_Type.Items[cb.ItemIndex] ..... select correct enum
The GUI code I am working with has a generic list of objects for the Items it holds, so I can't see a way around this.