Scenario:
There is an enumeration property and the FlagsAttribute is applied to the enumeration, i.e., several values can be written to this property. An editor allowing you to select several values is required.
Steps To Implement:
This functionality can be implemented via a custom property editors. There should be two separate editors - for Win (EnumPropertyEditorEx) and for Web (ASPxEnumPropertyEditorEx).
Win:
1. Create an EnumPropertyEditorEx class inherited from the built-in EnumPropertyEditor.
2. Override the CreateControlCore method and return the CheckedComboBoxEdit control if the FlagsAttribute is applied to the enumeration type.
3. Return the RepositoryItemCheckedComboBoxEdit object in the overridden CreateRepositoryItem method.
4. Add items to RepositoryItemCheckedComboBoxEdit in the SetupRepositoryItem method based on the possible enumeration values.
5. Subscribe to the RepositoryItemCheckedComboBoxEdit.ParseEditValue event to handle the situation when all items are unselected in the dropdown.
6. Subscribe to the RepositoryItemCheckedComboBoxEdit.CustomDisplayText event to show localized values.
Web:
1. Create an ASPxEnumPropertyEditorEx class inherited from the ASPxPropertyEditor class. The ASPxEnumPropertyEditor cannot be used as a base class, because it can work properly only with the ASPxComboBox editor which does not provide the multi-selection capability.
2. Return the ASPxGridLookup control in the overridden CreateEditModeControlCore method. Configure the ASPxGridLookup control to bind its Text property to the business object's enumeration property. To do this, perform the following steps:
2.1. Hide unnecessary UI elements from the embedded grid - grid lines and column headers, disable the selected row highlighting.
2.2. Create two columns - one for the row selection, and another to display values.
2.3. Use the in-memory data source (DataTable) to display grid rows based on the possible enumeration values.
2.4. Subscribe the inherited EditValueChangedHandler event handler to the ASPxGridLookup.TextChanged event to notify property editor when the control's value is changed.
3. Override the ReadEditModeValueCore method to set the lookup editor's text based on the enumeration property value.
4. Override the GetControlValueCore method to return the enumeration value based on the lookup editor's text.
See Also:
Implement Custom Property Editors
E444
S35490
S30849
Example Comments
Added By: Pawel Rymarczyk 1 at: 7/6/2013 1:11:36 AM
Hello,
How can I filter by flags enum property in the server mode? I mean filtering the ListView by AutoFilterRow.
Added By: Alex Silva 4 at: 4/4/2014 2:35:40 PMwould that same code for WEB
Added By: Dennis (DevExpress Support) at: 4/8/2014 12:45:41 AM@Alex: While we do not have a ready Web version of this example, you may find the code from the E1807 example helpful. Thanks.
Added By: Anatol (DevExpress Support) at: 4/9/2014 9:32:02 AMWeb version is added.