Sometime our dropdown lookup value are fixed and we don’t have any database table. In such situation we mostly make enum of our look up value.
But most of the time we are used to bind datasource of tables or list to combbox. So we might be wonder how to bind our enum to combobox.
Here is the simple way to bind combobox.
Say for example you have RoleTypes Enum.
public enum RoleTypes
{
Owner = 1,
Manager = 2,
AssitManager = 3,
Employee = 4
}
Now, to bind this enum to our combo box.
this.cmbUserRole.DataSource = Enum.GetValues(typeof(RoleTypes));
Set value to combobox.
this.cmbUserRole.SelectedItem = (RoleTypes)1;
To get value from combobox.
Convert.ToInt32((RoleTypes) this.cmbUserRole.SelectedItem);
No comments:
Post a Comment