Reputation: 14145
I have enum
public enum MyEnum
{
Choice = 1,
Choicee = 2,
Choiceee = 3
}
and I want to dynamically fill list with this enum values
var data = new List<ComboBoxItem>();
where ComboBoxItem
has two properties, Id
and Name
. Id should be enum int value and name should be enum Value like Choice or Choicee, ...
Upvotes: 1
Views: 433
Reputation: 23087
You can use Enum.GetValues
for it:
var values = Enum.GetValues(typeof(SearchOption)).Cast<SearchOption>()
.Select(x => new ComboBoxItem() { Id = (int)x, Name = x.ToString() }).ToList();
Upvotes: 5