In This Topic
A multi-value parameter allows you to input one or more than one parameter values in a report. You can choose a few options from the list or simply choose 'Select all' to select all options.
You need to check the Multivalue option to make a parameter multi-value, and optionally set Value for 'Select All'. If there are large number of options to choose from, choosing 'Select all' option creates an SQL query too long for an SQL Command to run. In such a case, you can specify a value to the multi-value parameter in Value for 'Select All' option.
The following procedure takes you through a step by step process of how to create a multi-value parameter and specify a value for selecting all options from the list. The report binds to the 'Products' table from 'NWIND.db' data source available on GitHub. It is a SQLite Provider, a custom data provider that works if System.Data.SQLite package is added and referenced in the ActiveReports.config file. See setting up the dependencies and configuration file as described in the topic Custom Data Providers.
Create a Report
In the ActiveReports Designer, create a new Page or an RDLX report.
Bind Report to Data
As you create a new report, Report Datasource dialog appears for you to configure the report data connection. You can also access this dialog by right-clicking the Data Sources node in the Report Explorer and then selecting the Add Data Source option.
Connect to a Data Source
- In the Report Data Source dialog, select the General page and enter the name of the data source.
- Under Type, select 'SQLite Provider'.
- In the Connection String, enter the path of the .db, here, 'NWIND.db', for example
Data Source=C:\Data\NWIND.db
- Click OK to close the dialog and complete the data source connection.
Create Dataset to Populate Parameter Values
- In the Report Explorer, right-click the Data Source (DataSource1 by default) node and select Add Data Set. See Add Dataset for more information.
- In the DataSet dialog that appears, select the Query page.
- Enter an SQL query like the following into the Query text box:
SELECT DISTINCT productName FROM Products
See Query Builder in Microsoft SQL Client and OLEDB Providers for more information on building SQL queries.
- Click the OK to close the dialog. You see the data set, DataSet1, and the field, productName, in the Report Explorer.
Add Report Parameter
- In the Report Explorer, right-click the Parameters node and select Add Parameter.
- In the Report - Parameters dialog that appears, add a name for the parameter, ReportParameter1.
- Ensure that the Data type matches that of the field (String for ProductName).
- Enter some text in the Text for prompting users for a value field.
- Select the check box next to Multivalue to allow users to select more than one item from the list.
- In the Value for 'Select All' option, enter '1'.
Provide List of Values for Report Parameter
- In the Report - Parameters dialog, go to the Available Values tab and select the From query radio button.
- Under the Dataset field, select the dataset created in the previous steps (DataSet1).
- Under the Value and Label fields, use the drop-down to select the field, productName.
- Click OK to close the dialog and add the parameter to the collection.
Add Dataset with Parameter
- In the Report Explorer, right-click the Data Source (DataSource1) node and select Add Data Set.
- In the DataSet dialog, on the Parameters page, click the Add (+) icon above the parameters list and add the following to the dataset to provide values for the parameters we add to the query in the step 3 below.
Name: ReportParameter1 Value: =Parameters!ReportParameter1.Value
Name: Parameter1 Value: =Parameters!ReportParameter1.Value
- On the Query page, enter a SQL query like the following in the Query text box:
SELECT * FROM products WHERE ProductName in (?) OR '1' in (?)
At run time, this query matches the selected product name and fetches data accordingly. If the user chooses 'Select all' (for which we have specified value '1'), then query after 'OR' is evaluated and data is fetched for all products.
- Click the Validate DataSet icon to validate the query and to populate the Fields list.
- Click the OK to close the dialog. You see the data set, DataSet2, and the fields in the Report Explorer.
Design report
- Drag-drop Table data region and bind it to the DataSet2.
- Fill-in the table with some fields, for example, [ProductName], [UnitPrice], and [UnitsOnOrder]. See page on Table data region for more information.
- Preview the report and observe the 'Parameters panel in the sidebar with Select all option at the top. For more information on Parameters pane, see Windows Forms Viewer.
Note: If the Available Values (queried or non-queried) for a parameter contain only some values from database and the Select all value is specified for the parameter, then at report preview, selecting the 'Select all’ checkbox shows all records from the database instead of only those present in the parameter. For example, if the database has four records and in the Available values there are only two records, with the Select all value specified, then on previewing report and selecting 'Select all' checkbox, all four records are shown instead of only two.