This example demonstrates how to create a wrapper class that obtains enumeration values and passes them to the ComboBox component's Data property.
Follow the steps below to bind the ComboBox component to an enumeration:
-
Create a wrapper class with two properties that specify an enumeration value and a text string that the ComboBox displays.
public class EducationDegree { // Specifies an enumeration value public EducationType Value { get; set; } // Specifies a text string public string DisplayName { get; set; } }
-
Create a generic extension method that gets the DisplayAttribute.Name property value from the enumeration's member.
-
Add the ComboBox component to your project and override the OnInitialized lifecycle method. This method creates a match between enumeration member integer and string values.
@code { // ... protected override void OnInitialized() { //... EducationDegrees = Enum.GetValues(typeof(EducationType)) .OfType<EducationType>() .Select(t => new EducationDegree() { Value = t, DisplayName = t.GetAttribute<DisplayAttribute>().Name }).ToList(); base.OnInitialized(); } }
(you will be redirected to DevExpress.com to submit your response)
