A discrete parameter is a single value, as opposed to a range parameter, which refers to a range of values. Text items (such as cities) are usually accessed through discrete parameters. Numeric items (such as employee salaries) are usually accessed through range parameters.
In this tutorial, you set a value for a discrete parameter to view a customer report that is based on one field. The report displays only those customers who live in the cities you have selected from a city list. The city list is derived from the default values for the City parameter. Those default values for the City parameter are encapsulated within the report.
To begin, you create a customer report with a city parameter. The report derives its data from the sample database that is shipped with Crystal Reports XI R2. When you instantiate the report in the code, you create an ArrayList that contains city names (Paris, Tokyo) and pass that ArrayList instance to a helper method that sets those city names as the current values for the city parameter. You then bind the report to the CrystalReportViewer control and view the report with only those customers that live in Paris and Tokyo displayed.
In the next part of the tutorial, you do the following:
In the final part of the tutorial, you code the button click event to retrieve any selected items from the ListBox control and set those to be the current values for the city parameter. The report redisplays and shows only those customers who live in the cities that have been selected within the ListBox control.
This tutorial can also be completed with classes of the CrystalReportViewer object model, although the ReportDocument object model is preferred. For more information on which object model to use, see Which Object Model Should I Use?.
To build this tutorial with the CrystalReportViewer object model, see Reading and Setting Discrete Parameters using the CrystalReportViewer object model.
Continue to Creating a Report with Parameters.
Tutorials and Sample Code | Tutorials' Sample Code Directory