绑定Enum枚举到combobox

public enum HemEnum
{
    [Description("none")]
    HemNone = -1,
    [Description("sewn")]
    Hemsew = 0,
    [Description("welded")]
    HemWeld = 1,
    [Description("double folded")]
    Hemdoublefold = 2
}


public static void LoadHemCombo(ComboBox cbo)
{
    cbo.DataSource = Enum.GetValues(typeof(HemEnum))
        .Cast()
        .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";
}

你可能感兴趣的:(WinForm)