Export (0) Print
Expand All

Adding the Subreport Parameter Code

Visual Studio 2005

You are now ready to add the parameter code for the subreport to the code-behind class. To begin, you create a private helper method, SetDateRangeForOrders().

To create and code the SetDateRangeForOrders() method

  1. Open the Web or Windows Form.
  2. From the View menu, click Code.
  3. At the top of the class, add two new constants below the existing PARAMETER_FIELD_NAME constant added during the previous tutorial.
    [Visual Basic]
    Private Const SUBREPORT_PARAMETER_FIELD_NAME As String = "OrderDateRange"
    Private Const SUBREPORT_NAME As String = "CustomerOrders"
    [C#]
    private const string SUBREPORT_PARAMETER_FIELD_NAME = "OrderDateRange";
    private const string SUBREPORT_NAME = "CustomerOrders";
  4. At the bottom of the class, create a new private method named SetDateRangeForOrders() with three parameters: ParameterFields, a string startDate, and a string endDate.
    [Visual Basic]
    Private Sub SetDateRangeForOrders(ByVal myParameterFields As ParameterFields, ByVal startDate As String, ByVal endDate As String)
    
    End Sub
    [C#]
    private void SetDateRangeForOrders(ParameterFields parameterFields, string startDate, string endDate)
    {
    }
  5. Within this method, declare and instantiate the ParameterRangeValue class.
    [Visual Basic]
    Dim myParameterRangeValue As ParameterRangeValue = New ParameterRangeValue()
    [C#]
    ParameterRangeValue parameterRangeValue = new ParameterRangeValue();
    Note   For the ParameterRangeValue class to be accessible, you must include an "Imports" [Visual Basic] or "using" [C#] statement at the top of the code-behind class for the CrystalDecisions.Shared namespace. (You added this declaration in Project Setup.)
  6. Set the StartValue property of the ParameterRangeValue instance to the startDate method parameter.
    [Visual Basic]
    myParameterRangeValue.StartValue = startDate
    [C#]
    parameterRangeValue.StartValue = startDate;
    Note   The StartValue and EndValue properties of the ParameterRangeValue class accept values of type Object. This generic type allows the range value that is passed in to be of many types, including: text, number, date, currency, or time.
  7. Set the EndValue property of the ParameterRangeValue instance to the endDate method parameter.
    [Visual Basic]
    myParameterRangeValue.EndValue = endDate
    [C#]
    parameterRangeValue.EndValue = endDate;
  8. Set the lower and upper boundaries to be bound-inclusive.
    [Visual Basic]
    myParameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive
    myParameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive
    [C#]
    parameterRangeValue.LowerBoundType = RangeBoundType.BoundInclusive;
    parameterRangeValue.UpperBoundType = RangeBoundType.BoundInclusive;
    Note   For BoundInclusive, the upper and lower range values are included in the range.

    You are now ready to assign the ParameterRangeValue instance to the parameter of the subreport.

  9. Retrieve the ParameterField instance from the ParameterFields indexed class, which is based on two indexed values: the subreport parameter field name and the subreport name. Pass in the two constant values that you declared at the top of the class.
    [Visual Basic]
    Dim myParameterField As ParameterField = myParameterFields(SUBREPORT_PARAMETER_FIELD_NAME, SUBREPORT_NAME)
    [C#]
    ParameterField parameterField = parameterFields[SUBREPORT_PARAMETER_FIELD_NAME, SUBREPORT_NAME];
  10. Call the Clear() method of the CurrentValues property of the ParameterField instance to remove any existing values from the CurrentValues property.
    [Visual Basic]
    myParameterField.CurrentValues.Clear()
    [C#]
    parameterField.CurrentValues.Clear();
  11. Add the ParameterRangeValue instance, which you created earlier, to the CurrentValues property of the ParameterField instance.
    [Visual Basic]
    myParameterField.CurrentValues.Add(myParameterRangeValue)
    [C#]
    parameterField.CurrentValues.Add(parameterRangeValue);

This step procedure has set start and end date values into a ParameterRangeValue instance and passed those values to the OrderDateRange parameter in the CustomerOrders subreport.

Continue to Adding TextBox Controls to Hold Range Parameter Values.

See Also

Tutorials: Reading and Setting Range Parameters With a Subreport | Tutorials and Sample Code | Tutorials' Sample Code Directory

Show:
© 2014 Microsoft