# 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](https://www.telerik.com/products/wpf/documentation/assets/01fec99516466948f197aca8448699e0/radpropertygrid_flagenumeditor_5.png)

You can define flag enum by setting **FlagsAttribute** as follows:

**Defining flag enum**

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

```VB.NET
	<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](http://msdn.microsoft.com/en-us/library/cc138362.aspx).

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

![FlagEnumEditor displaying enumeration values](https://www.telerik.com/products/wpf/documentation/assets/732b00919960a2ec63ad3a46963e8144/radpropertygrid_flagenumeditor_2.png)

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

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

```VB.NET
	<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**

```XAML
<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](https://www.telerik.com/products/wpf/documentation/assets/925e09a8ae430970e82a80bc92138975/radpropertygrid_flagenumeditor_3.png)

![FlagEnumEditor with All selected](https://www.telerik.com/products/wpf/documentation/assets/963c896ee766b044c68e94aca5bda0c3/radpropertygrid_flagenumeditor_4.png)

## 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**

```C#
[Flags]
public enum Permissions
{
    All = -1,
    None = 0,
    [Display(Name = "Reading")]
    Read = 1,
    [Description("Writing")]
    Write = 2,
    [Display(Name = "Executing")]
    [Description("Exe")]
    Execute = 4
}
```

```VB.NET
	<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](https://www.telerik.com/products/wpf/documentation/assets/bcc7d66f3902301851fadbfe2c6625ea/radpropertygrid_flagenumeditor_6.png)

> The `Display` attribute takes precedence over the `Description` attribute.

## See Also

* [Data Annotations](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/data-annotations)
* [Collection Editors](https://www.telerik.com/products/wpf/documentation/controls/radpropertygrid/features/collectioneditor)
