I am working lately a lot on Reflection and WCF. So there will be quite a few posts on around those two.
This is one relates to the former category.
Problem: You want to create a Combo Box at runtime and the items to be included in the Combo Box should be read from an enum.
Solution: Read the Enumeration at runtime and fill the items of the combo box with them.
First get all the values from the Enumeration:
String[] names = System.Enum.GetNames(typeof(enumToRead));
enumToRead is the Enum which you have to read the names from.
Now, iterating through each of the names, add it to the Combo Box:
foreach (string name in lstProvider)
{
cboxMyComboBox.Items.Add(name);
}
You can similarly get all the values in the enum by:
Array enumVal = Enum.GetValues(typeof(enumToRead)) ;