Edit this page

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:

Rad Property Grid Flag Enum Editor 5

You can define flag enum by setting FlagsAttribute as follows:

[C#] Example 1: Defining flag enum

[Flags]
public enum Permissions
{
    Read = 1,
    Write = 2,
    Execute = 4
}

[VB.NET] Example 1: Defining flag enum

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

Rad Property Grid Flag Enum Editor 2

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:

[C#] Example 2: Defining flag enum

[Flags]
public enum PermissionsAllNone
{
    All = -1,
    None = 0,
    Read = 1,
    Write = 2,
    Execute = 4
}

[VB.NET] Example 2: Defining flag enum

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

[XAML] Example 4: Defining 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 your FlagEnumEditor will look like:

Rad Property Grid Flag Enum Editor 3

Rad Property Grid Flag Enum Editor 4