Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Collapse]eXpressApp Framework
 [Expand]Fundamentals
 [Expand]Getting Started
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Functional Testing
 [Expand]Deployment
 [Collapse]Task-Based Help
  [Expand]Business Model Design
  [Expand]Application Model
  [Expand]Actions
  [Expand]Navigation
  [Expand]Views
  [Expand]List Editors
  [Collapse]Property Editors
    How to: Customize a Built-in Property Editor (ASP.NET)
    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]Templates
  [Expand]Filtering
  [Expand]Reporting
  [Expand]Dashboards
  [Expand]Scheduler and Notifications
  [Expand]Maps
  [Expand]Security
  [Expand]Workflow
  [Expand]Localization
  [Expand]Testing
  [Expand]Miscellaneous UI Customizations
 [Expand]Frequently Asked Questions
 [Expand]API Reference
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
[Expand]End-User Documentation

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.

Note

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.

Note

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

How would you rate this topic?​​​​​​​