Crystal Reports XI Release 2  

Addendum: Enhancements to the Discrete Parameters Code

If you have installed Visual Studio 2005 or Crystal Reports Developer you have access to the enhanced API that sets the discrete parameters in the Crystal report. The Crystal Reports Developer API helps minimize the amount of code that is needed to set the discrete parameters.

In the previous procedures, you learned to create the SetCurrentValuesForParameterField() helper method.

In this tutorial, you can delete the helper method and instead call the SetParameterValue() method of the ReportDocument class.

The SetParameterValue() method comes in the following overloaded methods:

You can pass in any type of object where the value satisfies the default values for the parameter field. The object can be an Array instance that stores a list of parameter values.

Prerequisites:

To use the SetParameterValue() method for Discrete Parameters

  1. Open the completed project for this tutorial.
  2. Open the Web or Windows Form.
  3. From the View menu, click Code.
  4. Within the ConfigureCrystalReports() method, above the line that binds the report to the ReportSource property of the CrystalReportViewer control, call the SetParameterValue() method from the CustomerByCity class. Pass the parameter field name and the parameter values in an Array instance to the method.
    [Visual Basic]
    customersByCityReport.SetParameterValue(PARAMETER_FIELD_NAME, arrayList.ToArray())
    [C#]
    customersByCityReport.SetParameterValue(PARAMETER_FIELD_NAME, arrayList.ToArray());

You are now ready to build and run the project, to read and set discrete parameters.

See Also

Tutorials: Reading and Setting Parameters with a Subreport | Tutorials: Reading and Setting Discrete Parameters | Tutorials and Sample Code | Tutorials' Sample Code Directory