Skip to main content
A newer version of this page is available. .

How to: 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

Mobile applications do not support displaying of a business class integer property as an enumeration, so the approach described in this topic cannot be implemented in the Mobile platform. If it is necessary to implement this scenario in your Mobile application, contact us using the Support Center.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e4925/how-to-display-an-integer-property-as-an-enumeration.

Consider the following SampleObject business class.

[DefaultClassOptions]
public class SampleObject : BaseObject {
    public SampleObject(Session session) : base(session) { }
    private string name;
    public string Name {
        get { return name; }
        set { SetPropertyValue("Name", ref name, value); }
    }
    private int integerProperty;
    public int IntegerProperty {
        get { return integerProperty; }
        set { SetPropertyValue("IntegerProperty", ref integerProperty, value); }
    }
}

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. In a WinForms module project, create a custom MyEnumIntPropertyEditor Property Editor by inheriting the EnumIntPropertyEditor<SampleEnum> class. 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 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 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 application.

WinForms

EnumIntPropertyEditor_Win

ASP.NET

EnumIntPropertyEditor_Web