Code Monkey

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

2 Responses to “Populate a list box from an Enum”

  1. 1
    Dtqqrjqh Says:

    Hey, i save funny photos

    here

  2. 2
    Wradayaccibly Says:

    Bite my shiny metal ass, assholes, you were joked!

Leave a Reply

© 2009 Code Monkey | Entries (RSS) and Comments (RSS)

Global Positioning System Gazettewordpress logo