Skip to main content
.NET 6.0+

Display an Integer Property as an Enumeration

  • 3 minutes to read

This topic describes how to display a business class integer property as an enumeration, in case you do not wish to modify (or cannot modify) the source code of this class.

Note

ASP.NET Core Blazor applications do not support displaying of a business class integer property as an enumeration.

Consider the following SampleObject business class.

[DefaultClassOptions]
public class SampleObject : BaseObject {
    public virtual string Name { get; set; }
    public virtual int IntegerProperty { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.

Assume that this class is located in an external assembly, and you cannot modify its code. The task is to display enumeration values instead of integers (e.g., Value1 for zero, Value2 for 1, etc.). Follow the steps below to learn how to solve this task.

  1. Implement an enumeration whose values will be mapped to integer values.

    public enum SampleEnum { Value1, Value2, Value3}
    
  2. Create a custom MyEnumIntPropertyEditor Property Editor by inheriting the EnumIntPropertyEditor<SampleEnum> class in the WinForms module project (MySolution.Module.Win). If your solution does not contain this project, add this editor to the WinForms application project (MySolution.Win). Note that your editor should be public.

    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Win.Editors;
    // ...
    [PropertyEditor(typeof(int), false)]
    public class MyEnumIntPropertyEditor : EnumIntPropertyEditor<SampleEnum> {
        public MyEnumIntPropertyEditor(Type objectType, IModelMemberViewItem model)
            : base(objectType, model) {  }
    }
    
  3. Run the Model Editor for the WinForms module project. Set the IModelCommonMemberViewItem.PropertyEditorType property of the BOModel | OwnMembers | IntegerProperty node to MyEnumIntPropertyEditor.
  4. In an ASP.NET Web Forms module project, create a custom MyEnumIntPropertyEditor Property Editor by inheriting the ASPxEnumIntPropertyEditor<SampleEnum> class. Note that your editor should be public.

    using DevExpress.ExpressApp.Editors;
    using DevExpress.ExpressApp.Web.Editors.ASPx;
    using DevExpress.ExpressApp.Model;
    // ...
    [PropertyEditor(typeof(int), false)]
    public class ASPxMyEnumIntPropertyEditor : ASPxEnumIntPropertyEditor<SampleEnum> {
        public ASPxMyEnumIntPropertyEditor(Type objectType, IModelMemberViewItem model)
            : base(objectType, model) {  }
    }
    
  5. Run the Model Editor for the ASP.NET Web Forms module project. Set the IModelCommonMemberViewItem.PropertyEditorType property of the BOModel | OwnMembers | IntegerProperty node to ASPxMyEnumIntPropertyEditor.

The images below illustrate the results in a WinForms application and an ASP.NET Web Forms application.

WinForms

EnumIntPropertyEditor_Win

ASP.NET Web Forms

EnumIntPropertyEditor_Web

See Also