This:
typeof(myEnum)
doesn't work because
myEnum
is your enum variable, not your enum type.
Instead you have to write the name of your enum-definition there - the equivalent to what is
HemEnum
in the source you linked:
public enum HemEnum
{
[Description("none")]
HemNone = -1,
[Description("sewn")]
Hemsew = 0,
[Description("welded")]
HemWeld = 1,
[Description("double folded")]
Hemdoublefold = 2
}
So, if your enum type is named "Abcdef" you have to write:
public static void LoadHemCombo(ComboBox cbo)
{
cbo.DataSource = Enum.GetValues(typeof(Abcdef))
I excluded the
myEnum
parameter of your method there because I don't know what it is supposed to be good for - it's not needed/used in the method.
edit after comment:
To use this with several different Enum-Types, make it a generic method:
public static void LoadCombo<TEnum>(ComboBox cbo)
{
cbo.DataSource = Enum.GetValues(typeof(TEnum))
.Cast<Enum>()
.Select(value => new
{
(Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description,
value
})
.OrderBy(item => item.value)
.ToList();
cbo.DisplayMember = "Description";
cbo.ValueMember = "value";
}
Example use:
public enum YourEnumType1
{
[Description("foo")]
abc,
[Description("bar")]
def,
[Description("baz")]
ghi
}
LoadCombo<YourEnumType1>(cbo);