Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 357357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:11:52+00:00 2026-05-12T12:11:52+00:00

I have an enumeration like Enum Complexity { NotSoComplex, LittleComplex, Complex, VeryComplex } And

  • 0

I have an enumeration like

Enum Complexity
{
  NotSoComplex,
  LittleComplex,
  Complex,
  VeryComplex
}

And I want to use it in a dropdown list, but don’t want to see such Camel names in list (looks really odd for users). Instead I would like to have in normal wording, like
Not so complex
Little complex (etc)

Also, my application is multi-lang and I would like to be able to display those strings localized, and I use a helper, TranslationHelper(string strID) which gives me the localized version for a string id.

I have a working solution, but not very elegant:
I create a helper class for the enum, with one member Complexity and ToString() overwritten, like below (code simplified)

public class ComplexityHelper
{
    public ComplexityHelper(Complexity c, string desc)
    { m_complex = c; m_desc=desc; }

    public Complexity Complexity { get { ... } set {...} }
    public override ToString() { return m_desc; }

    //Then a static field like this 

    private static List<Complexity> m_cxList = null;

    // and method that returns the status lists to bind to DataSource of lists
    public static List<ComplexityHelper> GetComplexities() 
    {
        if (m_cxList == null)
        {
           string[] list = TranslationHelper.GetTranslation("item_Complexities").Split(',');
           Array listVal = Enum.GetValues(typeof(Complexities));
           if (list.Length != listVal.Length)
               throw new Exception("Invalid Complexities translations (item_Complexities)");
           m_cxList = new List<Complexity>();
           for (int i = 0; i < list.Length; i++)
           {
             Complexity cx = (ComplexitylistVal.GetValue(i);
             ComplexityHelper ch = new ComplexityHelper(cx, list[i]);
             m_cxList.Add(ch);
           }
        }
        return m_cxList;
    }
}

While workable, I’m not happy with it, since I have to code it similarily for various enums I need to use in picklists.

Does anyone have a suggestion for a simpler or more generic solution?

Thanks
Bogdan

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:11:53+00:00Added an answer on May 12, 2026 at 12:11 pm

    Thank you all for all answers.
    Finally I used a combination from Rex M and adrianbanks, and added my own improvements, to simplify the binding to ComboBox.

    The changes were needed because, while working on the code, I realized sometimes I need to be able to exclude one enumeration item from the combo.
    E.g.

    Enum Complexity
    {
      // this will be used in filters, 
      // but not in module where I have to assign Complexity to a field
      AllComplexities,  
      NotSoComplex,
      LittleComplex,
      Complex,
      VeryComplex
    }
    

    So sometimes I want the picklist to show all but AllComplexities (in add – edit modules) and other time to show all (in filters)

    Here’s what I did:

    1. I created a extension method, that uses Description Attribute as localization lookup key. If Description attribute is missing, I create the lookup localization key as EnumName_
      EnumValue. Finally, if translation is missing I just split enum name based on camelcase to separate words as shown by adrianbanks. BTW, TranslationHelper is a wrapper around resourceMgr.GetString(…)

    The full code is shown below

    public static string GetDescription(this System.Enum value)
    {
        string enumID = string.Empty;
        string enumDesc = string.Empty;
        try 
        {         
            // try to lookup Description attribute
            FieldInfo field = value.GetType().GetField(value.ToString());
            object[] attribs = field.GetCustomAttributes(typeof(DescriptionAttribute), true);
            if (attribs.Length > 0)
            {
                enumID = ((DescriptionAttribute)attribs[0]).Description;
                enumDesc = TranslationHelper.GetTranslation(enumID);
            }
            if (string.IsNullOrEmpty(enumID) || TranslationHelper.IsTranslationMissing(enumDesc))
            {
                // try to lookup translation from EnumName_EnumValue
                string[] enumName = value.GetType().ToString().Split('.');
                enumID = string.Format("{0}_{1}", enumName[enumName.Length - 1], value.ToString());
                enumDesc = TranslationHelper.GetTranslation(enumID);
                if (TranslationHelper.IsTranslationMissing(enumDesc))
                    enumDesc = string.Empty;
            }
    
            // try to format CamelCase to proper names
            if (string.IsNullOrEmpty(enumDesc))
            {
                Regex capitalLetterMatch = new Regex("\\B[A-Z]", RegexOptions.Compiled);
                enumDesc = capitalLetterMatch.Replace(value.ToString(), " $&");
            }
        }
        catch (Exception)
        {
            // if any error, fallback to string value
            enumDesc = value.ToString();
        }
    
        return enumDesc;
    }
    

    I created a generic helper class based on Enum, which allow to bind the enum easily to DataSource

    public class LocalizableEnum
    {
        /// <summary>
        /// Column names exposed by LocalizableEnum
        /// </summary>
        public class ColumnNames
        {
            public const string ID = "EnumValue";
            public const string EntityValue = "EnumDescription";
        }
    }
    
    public class LocalizableEnum<T>
    {
    
        private T m_ItemVal;
        private string m_ItemDesc;
    
        public LocalizableEnum(T id)
        {
            System.Enum idEnum = id as System.Enum;
            if (idEnum == null)
                throw new ArgumentException(string.Format("Type {0} is not enum", id.ToString()));
            else
            {
                m_ItemVal = id;
                m_ItemDesc = idEnum.GetDescription();
            }
        }
    
        public override string ToString()
        {
            return m_ItemDesc;
        }
    
        public T EnumValue
        {
            get { return m_ID; }
        }
    
        public string EnumDescription
        {
            get { return ToString(); }
        }
    
    }
    

    Then I created a generic static method that returns a List>, as below

    public static List<LocalizableEnum<T>> GetEnumList<T>(object excludeMember)
    {
        List<LocalizableEnum<T>> list =null;
        Array listVal = System.Enum.GetValues(typeof(T));
        if (listVal.Length>0)
        {
            string excludedValStr = string.Empty;
            if (excludeMember != null)
                excludedValStr = ((T)excludeMember).ToString();
    
            list = new List<LocalizableEnum<T>>();
            for (int i = 0; i < listVal.Length; i++)
            {
                T currentVal = (T)listVal.GetValue(i);
                if (excludedValStr != currentVal.ToString())
                {
                    System.Enum enumVal = currentVal as System.Enum;
                    LocalizableEnum<T> enumMember = new LocalizableEnum<T>(currentVal);
                    list.Add(enumMember);
                }
            }
        }
        return list;
    }
    

    and a wrapper to return list with all members

    public static List<LocalizableEnum<T>> GetEnumList<T>()
    {
            return GetEnumList<T>(null);
    }
    

    Now let’s put all things together and bind to actual combo:

    // in module where we want to show items with all complexities
    // or just filter on one complexity
    
    comboComplexity.DisplayMember = LocalizableEnum.ColumnNames.EnumValue;
    comboComplexity.ValueMember = LocalizableEnum.ColumnNames.EnumDescription;
    comboComplexity.DataSource = EnumHelper.GetEnumList<Complexity>();
    comboComplexity.SelectedValue = Complexity.AllComplexities;
    
    // ....
    // and here in edit module where we don't want to see "All Complexities"
    comboComplexity.DisplayMember = LocalizableEnum.ColumnNames.EnumValue;
    comboComplexity.ValueMember = LocalizableEnum.ColumnNames.EnumDescription;
    comboComplexity.DataSource = EnumHelper.GetEnumList<Complexity>(Complexity.AllComplexities);
    comboComplexity.SelectedValue = Complexity.VeryComplex; // set default value
    

    To read selected the value and use it, I use code as below

    Complexity selComplexity = (Complexity)comboComplexity.SelectedValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf Array already has a native indexOf method. Changing… May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Your DateAdd function is actually finding the Saturday of the… May 12, 2026 at 5:39 pm
  • Editorial Team
    Editorial Team added an answer Try CDF(0,1).sin() # or ComplexDoubleField(0,1) CDF is just a shorthand… May 12, 2026 at 5:39 pm

Related Questions

I'm trying to use the Html.DropDownList extension method but can't figure out how to
I'm required to maintain a few VB6 apps, and I have run into a
I have this serious problem. I have an enumeration within 2 namespaces like this:
I have what amounts to a multi-dimensional array. int[][][] MyValues; What I want is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.