Assume you have define an enum like :

public enum LanguageCollection : int
{
    English = 0,
    简体中文,
    Español,
    Tuurkish,
    Français
}

Is it possible to populate all enum item to a dropdownlist control without hard code each enum name ? The answer is Yes.

Here is sample code :

this.menuCBLanguage.Items.Clear();
for (int i = 0; i < Enum.GetNames(typeof(LanguageCollection)).Length; i++)
{
     this.menuCBLanguage.Items.Add(Enum.GetName(typeof(LanguageCollection), i));
}

One Response to “List enum item names using C#”

  1. very informative page

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2012 CodeEase.com Suffusion theme by Sayontan Sinha