Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

16.09 Subreports

Modifying Subreport Parameters

As you saw earlier in this chapter, if you want to modify the parameters in a subreport, you can pass the subreport name to the SetParameterValue() method. Of course, this method is only available with the ReportDocument class.

If you want complete access to all the properties of a subreport’s parameters, you need to get a reference to the actual parameter. The ReportDocument.ParameterFields() indexer is overloaded so that you can pass it the subreport name as the second parameter. This returns the parameter from the subreport as a ParameterFieldDefinition object and you have access to all of its properties. As an example, Step 1 from Listing 16-7 has been modified to demonstrate getting a parameter from a subreport.

'Step 1:Get a reference to the parameter field to modify
myParameterFieldDefinition = _
myReport.DataDefinition.ParameterFields("Location", "Subreport1")

For the rare times you want to modify a subreport parameter using the viewer object, the ParameterFieldInfo property of the viewer object has an overloaded indexer. In addition to passing it the parameter name, you can also pass the name of a subreport. Passing the subreport name gives you access to all the parameters on a subreport. If you pass an empty string as the subreport name, the main report’s parameters are referenced.

As an example, Step 2 from Listing 16-8 has been modified to demonstrate getting a parameter from a subreport. The rest of the code in Listing 16-8 works as is and modifies the subreport parameter as expected.

'Step 2: Reference the ParameterField object
myParameterField = CrystalReportViewer1.ParameterFieldInfo("DateRange", "Subreport1")