Tuesday, October 2, 2012

WPF Sorted Enum ComboBox

In this sample; the value displayed in the combo box is the Enum attribute value and not the Enum value itself.

This would therefore give you the flexibility to have a more descriptive text to display.

public enum Country : int
    [Description("Australia (AUS)")]
    AUS = 0,

    [Description("United States (USA)")]
    USA = 1,

    [Description("United Kingdom (GBR)")]
    GBR = 2,

    [Description("France (FRA)")]
    FRA = 3,

    [Description("Germany (GER)")]
    GER = 4,

    [Description("Spain (ESP)")]
    ESP = 5,

    [Description("Jamaica (JAM)")]
    JAM = 6,

    [Description("Japan (JPN)")]
    JPN = 7,

    [Description("Uruguay (URU)")]
    URU = 8

But then there is a problem of displaying the value in order of the Enum attribute.

So I wrote a sample app to solve this problem.  

Enum ComboBox

Please let me know if this helps you.

No comments: