List enum item names using C#

Published on Tuesday, August 24, 2010
c#

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));
}