23 Jan
Populate a list box from an Enum
Have you ever needed to populate a listbox from an Enum and have the numeric value of the enum be the value for the listbox? Well here’s how.
public enum Status
{
Progress = 1,
Modify = 2,
Review = 3,
Completed = 4,
Terminated = 5
}
private void loadStatus()
{
Array arr = System.Enum.GetValues(typeof(Status));
for (int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0);i++)
{
string txt = Enum.GetName(typeof(Status), arr.GetValue(i));
int nval = (int)arr.GetValue(i);
string val = nval.ToString();
ListItem li = new ListItem(txt,val);
StatusListBox.Items.Add(li);
}
}


Hey, i save funny photos
here
December 22nd, 2008 at 5:31 pmBite my shiny metal ass, assholes, you were joked!
January 2nd, 2009 at 8:32 pm