Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

16.06 Default Values and Current Values

Defining Default Values and Current Values

Before you can use the parameter classes to pass values to the parameter objects, you need to understand how values are classified. When a report with parameters loads, the user is shown a dialog box to enter values for each parameter. The dialog box frequently shows a pre-populated list of values to choose from. The values in the list are called Default Values. When the user enters a value for a parameter, it could be a single value or possibly multiple values. The value that the user enters is called the Current Value.

A .NET program can modify either the default values or the current values. To design your application so that the user enters all the values on a .NET form and doesn’t get the parameter dialog box, set the current values with your application. On the other hand, you might let the user get prompted with the parameter dialog box and you will set the default values listed. For example, you can simulate a data-bound listbox by setting the default value list to show data stored in a table. This is done by overriding the default values that were assigned to the parameter when the report was designed.

When setting parameter values, either set the current value or the default values, but not both. Setting the current value and setting the default values are mutually exclusive operations. If you set a parameter’s current value, then the user never sees the dialog box and the default values are ignored. When you want the user to enter a parameter, set the default values but not the current values. Since there is no current value, the user will be prompted to enter it.

Considering that the parameter field classes of the ReportDocument class and the CrystalReportViewer class look so similar, you might assume that once you learn how to program with one class, you automatically know how to program with the other class. Unfortunately, this is not the case. Although there are many similarities, the differences are significant enough that you have to be very careful to make sure you understand the nuances between them. Paying close attention to the code examples in this section will save you headaches.

From a conceptual standpoint, the parameter objects in the ReportDocument class and the CrystalReportViewer class are the same. Both of them can modify the current values and default values of a parameter. This leads to the question of which one should you use in your application. This is determined by the other functionality your application implements. For most scenarios, you should use the ReportDocument class for manipulating reports. The CrystalReportViewer class is primarily used for setting display properties. Although it does have some functionality for modifying a report, it is very limited. It can be useful when using web services, but other than that you are best off always using the ReportDocument class. You should also note that SAP technical documents officially state that you cannot make report modifications with both classes simultaneously. You have to use one or the other. Thus, stick with the ReportDocument class at all times and you’ll be fine.