How to: Filter a Report Parameter's Lookup
- 2 minutes to read
When your report has a report parameter of a persistent type, the parameter value is specified using a lookup editor. However, if there is a large amount of objects in the lookup, it may be inconvenient to scroll and select the desired parameter value. This example describes how to filter the parameter’s lookup to reduce the number of available values.
Note
- This example is applicable to WinForms and ASP.NET Web Forms applications. However, in WinForms applications, the lookup editor already has the built-in filtering support. So, the customizations demonstrated here make sense in ASP.NET Web Forms applications only.
In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).
Filter the Lookup Parameter Using the Additional Data Source
Add an extra CollectionDataSource data source to your report from the Toolbox. In the Properties window, set the DataSourceBase.ObjectTypeName property to the type of the parameter to be filtered. Specify the desired filter using the CollectionSourceBase.Criteria property.
Determine the key type used in the parameter’s type (passed to ObjectTypeName in the previous step). Create a parameter of the same key type (e.g., Guid or int). Enable “Support the collection of standard values”. Specify the DataSource, created in the previous step. Set DisplayMember to the name of the property storing the human-readable identifier of the parameter (e.g., Name). Set ValueMember to the name of the parameter’s key property (e.g., Oid).
As the result, the parameter’s lookup will be filtered according to the specified criteria.
Use Cascading Parameters
The previous section described how to specify a static filter at design time. However, the filtering expression can include other parameter values, so you can use Cascading Parameters to change the filter an runtime when previewing the report. Note that the filtering is performed on the client side in this instance.
Add the Filter parameter of a string type. Pass the criteria that included a reference to the Filter parameter to the FilterString property of the parameter to be filtered (e.g., “Contains([Name], ?filter)”).
As the result, the parameter’s lookup will be accompanied with the Filter input field. The lookup will be filtered according to the specified Filter text.