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
Question 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 PM would 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 AM Web version is added.
Added By:
Leong Vai Long at:
5/14/2014 3:22:04 AM Hi, I had try this method for the XAF web version. The question is how i want to use the XAF Display Name to show in the lookup? bcos I only see the enum values.
Thanks.
Added By:
Dennis (DevExpress Support) at:
5/14/2014 9:09:47 AM @Leong: This particular functionality is not implemented in this example solution. You would need to modify the E689.Module.Web.Editors.EnumPropertyEditorEx class to achieve this. While we do not have a ready sample, feel free to contact our ASP.NET team on how to implement your task with the ASPxGridLookup component used in this example. Once you receive a solution for this component, it can be easily integrated in XAF.
Added By:
Leong Vai Long at:
5/14/2014 10:46:46 PM Hi Dennis,
1. Is it possible to change the ASPXGridLookup with the ASPXDropDownEdit? This is the link http://blog.zerosharp.com/three-ways-to-store-a-list-of-currency-codes-in-xaf/#disqus_thread, but this example use the string, how to convert it to enum?
2. How to contact your ASP.NET team to implement my task with the ASPXGridLookup?
Thanks.