How do i show enum values in a combo-box? The code below result in the combobox having all displayed names being \"caseHandler.cState\". I wanted it to have the actual names
Here My Code , you can have text and value together and fill Combobox
public enum LayerType : int
{
[Description("محوطه")]
Area = 1,
[Description("ساختمان")]
Building = 2,
[Description("بارانداز")]
Wharf = 3,}
drpLayer.DataSource = Enum.GetValues(typeof(LayerType))
.Cast()
.Select(value => new
{
(Attribute.GetCustomAttribute(value.GetType().GetField(value.ToString()), typeof(DescriptionAttribute)) as DescriptionAttribute).Description,
value
})
.OrderBy(item => item.value)
.ToList();
drpLayer.DisplayMember = "Description";
drpLayer.ValueMember = "value";