Share via


Tutorial: Reading and Setting Range Parameters for a Subreport

Introduction

In the previous tutorial, Tutorial: Reading and Setting Discrete Parameters, you have learned how to create a report with a discrete parameter, and how to write code to set that parameter at runtime – both with hard-coded parameter values and parameter values that are passed from a ListBox or TextBox control.

In this tutorial, you learn how to add range parameters to a subreport.

You need to make four modifications to the project that you have previously created:

  • You add a subreport into the original report.

    This subreport addresses the Orders table of the Xtreme database. The Orders table is related to the Customers table that is used in the previous tutorial by a Customer ID foreign key.

  • You add a range parameter to the subreport that filters by a range of order dates.

  • You add two Text controls to the form: orderStartDate, and orderEndDate, to set the order date range at runtime.

  • You modify the SetCurrentValuesForParameter() method that you have created in the previous tutorial.

    This method creates a ParameterRangeValue instance that contains the startDate and endDate values, and then passes that ParameterRangeValue instance into the range parameter inside the subreport.

When you have completed this tutorial, you can filter the values that are displayed on the report at runtime. The code that you add limits the number of cities that are displayed in the main report, and limits the range of order dates to be displayed in the subreport.

This tutorial can also be completed with classes of the ReportDocument object model, see Tutorial: Reading and Setting Parameters with a Subreport. For more information about object model usage, see Which Object Model Should I Use?.

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_ParametersSubrpt
  • C# Windows project: CS_Win_CRVObjMod_ParametersSubrpt
  • Visual Basic Web Site: VB_Web_CRVObjMod_ParametersSubrpt
  • Visual Basic Windows project: VB_Win_CRVObjMod_ParametersSubrpt

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

In this section: