2-Jul-04 (Created: 2-Jul-04) | More in 'CS-dotnet'

An easy way to fill a combo box or a list box from an enum.

Credits: Paul Montgomery

To set a combo box ( or list box ) to all of the values in an enum, do the following.


this.ComboBox1.DataSource 
   = Enum.GetNames( typeof ( YourEnum ));

Then to get it back out.


YourEnum val 
   = (YourEnum) Enum.Parse(typeof(YourEnum)
          ,comboBox1.SelectedItem.ToString());