How can we display the contents of an enum in a ComBoBox?

 Posted by Ddd on 2/23/2011 | Category: Others Interview questions | Views: 3330 | Points: 40
Answer:

Create an enum and using Reflection, bind the enum contents with the DataSource
property of ComBoBox

ex:
enum WeekDays
{
Sunday,
Monday,
Tuesday
}

Write this statement in Form_Load event handler

combobox1.DataSource=Enum.GetValues(typeof(WeekDays));



. GetValues is a static method of Enum class and
retrieves an array of the values of the constants in a specified enumeration.//

. It expects the enum name as the parameter and the typeof operator retreives the

. contents of the user-defined enum


| Alert Moderator 

Comments or Responses

Login to post response