Galaktikasoft

Enum Property Editor

Enum Property Editor

Used for enumeration properties which are decorated with FlagsAttribute, displays these properties using CheckedComboBox or CheckedListBox controls. Standard manner of displaying is also supported.

The following code snippet demonstrates EnumPropertyEditorObject business class that includes MyDaysOfWeek and MyMonths enum type properties with FlagsAttributte.

public class EnumPropertyEditorObject : BaseObject
{
    public EnumPropertyEditorObject(Session session) : base(session) { }

    public string LecturerName
    {
        get { return GetPropertyValue("LecturerName"); }
        set { SetPropertyValue("LecturerName", value); }
    }
    
    public MyDaysOfWeek Day
    {
        get { return GetPropertyValue("Day"); }
        set { SetPropertyValue("Day", value); }
    }
    
    public MyMonthes? Month
    {
        get { return GetPropertyValue<MyMonthes?>("Month"); }
        set { SetPropertyValue<MyMonthes?>("Month", value); }
    }
    
    public Subject Subject
    {
        get { return GetPropertyValue("Subject"); }
        set { SetPropertyValue("Subject", value); }
    }
}

[Flags]
public enum MyDaysOfWeek
{
    None,
    [ImageName("Monday")]
    Monday = 1,
    [ImageName("Tuesday")]
    Tuesday = 2,
    [ImageName("Wednesday")]
    Wednesday = 4,
    [ImageName("Thursday")]
    Thursday = 8,
    [ImageName("Friday")]
    Friday = 16,
    [ImageName("Saturday")]
    Saturday = 32,
    [ImageName("Sunday")]
    Sunday = 64,
    [ImageName("Holiday")]
    Holiday = Saturday | Sunday,
    [ImageName("WorkDays")]
    WorkDays = Monday | Tuesday | Wednesday | Thursday | Friday
}

[Flags]
public enum MyMonthes
{
    January = 1,
    February = 2,
    March = 4,
    April = 8,
    May = 16,
    Spring = March | April | May,
    June = 32,
    July = 64,
    August = 128,
    Summer = June | July | August,
    September = 256,
    October = 512,
    November = 1024,
    Autumn = September | October | November,
    December = 2048,
    Winter = January | February | December
}

public enum Subject
{
    Biology,
    Chemistry,
    Mathematics
}

You can view the code used in this lesson in the Xafari.XtraEditors.Module | Editors| EnumPropertyEditorObject.cs file of the Xafari XtraEditors demo installed with the product.

To use Enum Property Editor, invoke Model Editor and focus the corresponding BOModel|Class|OwnMembers|Member node, set PropertyEditorType property to the WinEnumPropertyEditor (or WebEnumPropertyEditor) value.

Enum Property Editor

Set EnumViewType property to specify the control to display enumeration.

Standard value specifies the simple combo box, in the same manner as XAF displays enumeration properties. CheckedComboBox and CheckedListBox allow checking a few items. Enum Property Editor exposes a number of additional properties for the flexible customization:

ColumnsCount property specifies the count of columns within control when using CheckedComboBox.

DisplayItemImages property specifies whether CheckedListBox to display item images.

DefaultItemImageName property specifies the default image. The code snippet above demonstrates, how to define item images using ImageName Attribute. In a situation when defined images are not available, the application uses the default image.

AllItemsInclude property specifies whether or not to show the “All” item.

AllItemsItemImageName property specifies the image for the “All” item.

AllItmsName property specifies the caption for the “All” item.

After the all customization is completed, run the WinForms or ASP.NET application. Select the appropriate item in the navigation control and click the New Action. In the invoked Detail View you can use Xafari Enum Property Editor.

The Image below shows WinForms application screenshot where Day property is displayed via the CheckedListBox control with custom images. Month property is displayed via the CheckedComboBox control, the count of columns is 3. Both properties are displayed with “All” item.

The image below shows ASP.NET application screenshots. Day property is displayed via the CheckedListBox without images, “All” item has “Select All” caption. Month property is displayed via the CheckedComboBox control, the count of columns is 2. “All” item is not displayed.

Label Property Editor

In order to learn more about powerful Xafari tools we invite you to read our blogpost about Vertical Grid Property Editor which displays referenced object in tabular form and provides compact layout of data in Detail View.