How to: Filter a Report Parameter's Lookup
- 3 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.
- This example is applicable to WinForms and ASP.NET 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 applications only. Mobile applications do not support the report preview mechanism, so the approach described in this topic cannot be implemented in the Mobile platform.
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T319024.
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.