Log In
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Collapse]eXpressApp Framework
 [Expand]Getting Started
 [Expand]Design-Time Features
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]List Editors
  [Collapse]Property Editors
    How to: Customize a Built-in Property Editor (ASP.NET)
    How to: Customize a Built-in Property Editor (Mobile)
    How to: Customize a Built-in Property Editor (WinForms)
    How to: Disable and Hide Property Editors Based on a Business Rule
    How to: Display an Integer Property as an Enumeration
    How to: Implement a Property Editor Based on a Custom Control (WinForms)
    How to: Implement a Property Editor Based on Custom Controls (ASP.NET)
    How to: Implement a Property Editor Using a DevExpress WinForms Control
    How to: Supply Predefined Values for the String Property Editor Dynamically (ASP.NET)
    How to: Supply Predefined Values for the String Property Editor Dynamically (WinForms)
    How to: Use Criteria Property Editors
  [Expand]Scheduler and Notifications
  [Expand]Miscellaneous UI Customizations
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
This documentation page describes implementations made in our v17.2 release cycle. To learn about functionality shipping with v18.1, navigate to our updated help file experience at docs.devexpress.com. Learn More

How to: Supply Predefined Values for the String Property Editor Dynamically (WinForms)

This topic describes implementation of a custom Property Editor for a Windows Forms application. A custom Property Editor used to edit a business object's CultureCode (locale) property of the String type is implemented here. The dropdown list of the Property Editor's control will display the cultures installed in an end-user's Windows operating system.


You can also specify predefined values in the Model Editor using the IModelCommonMemberViewItem.PredefinedValues property. This approach is much simpler because it does not require extra coding, but you will be unable to update the values list dynamically in code in this instance.

The image below shows the resulting Property Editor:

By default, XAF creates the StringPropertyEditor for String type properties. This Property Editor displays a dropdown list of items if the corresponding BOModel | <Class> | OwnMembers | <Member> node's RowCount property is set to 0 and the PredefinedValues property contains a predefined list values for the dropdown. However, if you do not know the values before run time it is necessary to implement a custom Property Editor.

Since you are going to use a control supplied by DevExpress, implement a custom Property Editor by overriding the DXPropertyEditor class methods. You can inherit this class directly, or inherit one of its descendants (e.g., StringPropertyEditor). Note that your editor should be public. So, the following methods must be overridden.
  1. Override the CreateControlCore method to return the ComboBoxEdit control.
  2. Override the CreateRepositoryItem method to return RepositoryItemComboBox type item, because it is the appropriate type for the ComboBoxEdit control.
  3. Override the SetupRepositoryItem method to populate the control's dropdown list with items. We use the CultureInfo.GetCultures method to retrieve the cultures installed.

To specify that the implemented Property Editor can be used for the String type properties, the PropertyEditor attribute is applied:

In this example, we apply the ModelDefaultAttribute attribute to use the implemented Property Editor for a business object's CultureCode property:

Here, the ModelDefault attribute specifies the PropertyEditorType property of the Application Model's IModelMember node that defines the CultureCode property. Alternatively, you can do it via the Model Editor.


You can see the code demonstrated here along with more examples on custom property editors in the Feature Center Demo installed with XAF.

Expanded See Also

Is this topic helpful?​​​​​​​