List enum item names using C#
2010-08-24
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));
}