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
 End-User Documentation

How to: Use Criteria Property Editors

This topic details the specifics of using Criteria Property Editors in an XAF application. An application that allows end-users to design and save filtering criteria at runtime is demonstrated here.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E932.

To create the sample application, do the following:

  1. Define business classes whose List Views will later be filtered.
  2. Define the FilteringCriterion business class that represents filtering criteria for the Product's List View.
  3. Create a custom View Controller that contains an Action used to filter the List View.

To begin building the sample application, create a new XAF application solution named HowToUseCriteriaPropertyEditors using the DevExpress v17.1 XAF Solution Wizard Template Gallery.Built-in Visual Studio Templates.

Expanded Step 1 - Add the Product and Person Business Classes

Right-click the HowToUseCriteriaPropertyEditors.Module project, and choose Add DevExpress Item | New Item... to invoke Template Gallery. Then select the XAF Business Object | XPO Business Object project item, name it Product, and press Add Item. You will get an automatically generated code file with a single class declaration. Replace the automatically generated class declaration with the following code, defining a class with four persistent properties of different types:

The Manager reference property is of the Person type, that is the class from the Business Class Library. Add a Person item to the ShowNavigationItem and to the New action, via the Model Editor (see Add an Item to the Navigation Control and Add an Item to the New Action).

Expanded Step 2 - Define the FilteringCriterion Business Class

Add the Domain Object named FilteringCriterion to the HowToUseCriteriaPropertyEditors.Module project, and replace the automatically generated class declaration with the following code:

Objects of this class represent filtering criteria. The Description field contains the text that describes a criterion. These descriptions will be used to fill a drop-down list of possible filters. The Criterion property holds a criterion. To use the built-in XAF Criteria Property Editors, the property that holds a criterion must have the CriteriaOptionsAttribute applied. The attribute's parameter is the name of an additional Type property, which specifies the objects' type used in the construction of the criterion. In this sample, it is the ObjectType property. Additionally, the CriteriaOptions attribute changes the default Property Editor for the property:

  • CriteriaPropertyEditor is used in Windows Forms applications
  • ASPxCriteriaPropertyEditor is used in ASP.NET Web applications

Expanded Step 3 - Create a Custom List View Controller

Add the following CriteriaController class to the HowToUseCriteriaPropertyEditors.Module project.

This Controller adds the FilteringCriterion SingleChoiceAction and populates the Action's dropdown list with all the existing FilterCriterion objects whose ObjectType matches the type of objects displayed in the current List View.

The FilteringCriterion Action applies the criterion selected in the dropdown list to the List View. Note that to convert the Criterion property's value of a FilterCriterion object to the DevExpress.Data.Filtering.CriteriaOperator object, you need to call the CriteriaEditorHelper.GetCriteriaOperator static method. This method takes three parameters. The string parameter represents the criterion to be converted. The Type parameter specifies the object type for which the criterion is constructed. The ObjectSpace parameter specifies any IObjectSpace that contains objects of the specified type.

Note

You should not use the CriteriaOperator.Parse method in this scenario. Criteria Property Editors can generate Criteria Strings containing Object Parameters, which are specific to XAF and cannot be parsed by CriteriaOperator.Parse.

Now you can run the Windows Forms or ASP.NET application, create several Person, Product and FilterCriteria objects, and then try the FilteringCriterion action.

The Criteria Property Editors are also demonstrated in the Property Editors | Criteria Properties section in the Feature Center demo installed with XAF. By default, the Feature Center demo is installed in %PUBLIC%\Documents\DevExpress Demos 17.1\Components\eXpressApp Framework\FeatureCenter. The ASP.NET version of this demo is available online at http://demos.devexpress.com/XAF/FeatureCenter/.

Expanded See Also

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