Share via


Tutorial: Reading and Setting Discrete Parameters

Introduction

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 for Visual Studio. 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:

  • Create a method that gets all the default values and returns them in an ArrayList.
  • Add a ListBox control to the form and populate it from the ArrayList.
  • Add a Button control to redisplay the report based on ListBox selections.

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.

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Web Site: CS_Web_CRVObjMod_Parameters
  • C# Windows project: CS_Win_CRVObjMod_Parameters
  • Visual Basic Web Site: VB_Web_CRVObjMod_Parameters
  • Visual Basic Windows project: VB_Win_CRVObjMod_Parameters

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section: