FlagEnumEditor

RadPropertyGrid now supports editing bit flag enum by exposing a new editor – FlagEnumEditor. It enables the user to store any combination of the values that are defined in the enumerator list:

FlagEnumEditor Overview

You can define flag enum by setting FlagsAttribute as follows:

Defining flag enum

[Flags] 
public enum Permissions 
{ 
    Read = 1, 
    Write = 2, 
    Execute = 4 
} 
<Flags()> 
Public Enum Permissions 
    Read = 1 
    Write = 2 
    Execute = 4 
End Enum 

Each element should contain name and a value (which should be degree of 2 – 1, 2, 4, 8, 16, etc.).

You can find more information about enum and flag enum in this article.

Once you define your flag enum, you can edit it in RadPropertyGrid as follows:

FlagEnumEditor displaying enumeration values

Furthermore, if you define zero and -1 values in your flag enum (meaning no flags are set and all flags are set correspondingly), you can benefit from the built-in functionality for selecting and unselecting the elements of the enum:

Defining the flag enum

[Flags] 
public enum PermissionsAllNone 
{ 
    All = -1, 
    None = 0, 
    Read = 1, 
    Write = 2, 
    Execute = 4 
} 
<Flags()> 
Public Enum PermissionsAllNone 
    All = -1 
    None = 0 
    Read = 1 
    Write = 2 
    Execute = 4 
End Enum 

Do not define values with 0 and -1 values if you do not mean to use them as select no flag and select all flags.

You can manually define your FlagEnumEditor in XAML, like so:

Defining the FlagEnumEditor

<telerik:PropertyDefinition Binding="{Binding Permission}"> 
    <telerik:PropertyDefinition.EditorTemplate> 
        <DataTemplate> 
            <telerik:FlagEnumEditor Value="{Binding Permission}" EnumType="my:Permissions"/> 
        </DataTemplate> 
    </telerik:PropertyDefinition.EditorTemplate> 
</telerik:PropertyDefinition> 

Thus the FlagEnumEditor will look like this:

FlagEnumEditor with None selected

FlagEnumEditor with All selected

Display and Description Attributes

As of R2 2022 SP1, the FlagEnumEditor control supports the Display and Description attributes which let you specify user-friendly and/or localizable strings for the enum values used in the user interface.

Using the Display and Description attributes

[Flags] 
public enum Permissions 
{ 
    All = -1, 
    None = 0, 
    [Display(Name = "Reading")] 
    Read = 1, 
    [Description("Writing")] 
    Write = 2, 
    [Display(Name = "Executing")] 
    [Description("Exe")] 
    Execute = 4 
} 
<Flags> 
Public Enum Permissions 
    All = -1 
    None = 0 
    <Display(Name := "Reading")> 
    Read = 1 
    <Description("Writing")> 
    Write = 2 
    <Display(Name := "Executing")><Description("Exe")> 
    Execute = 4 
End Enum 

Enum Values from the Display and Description attributes

The Display attribute takes precedence over the Description attribute.

See Also

In this article