Skip to main content

Report Parameters with Predefined Static Values

  • 3 minutes to read

You can create a list of predefined values for a report parameter. When you open a report’s Print Preview, you can select a value from this list in the Parameters Panel.

Create a report parameter with predefined static values

Create a List of Predefined Values in the Report Designer

Follow the steps below to create a parameter with a list of predefined static values in the Visual Studio Report Designer:

  1. Create a report parameter as described in this topic: Create a Report Parameter.
  2. Set the parameter’s Value Source option (that corresponds to the ValueSourceSettings property) to StaticListLookUpSettings. A grid appears in the Add New Parameter dialog and allows you to specify a list of static parameter values. Each value should have a description. This description is displayed in the Parameters panel.

    Specify static values for a report parameter

Create a List of Predefined Values in Code

To specify predefined static values for a parameter in code, create a StaticListLookUpSettings class instance and add static values to its LookUpValues collection. Assign the StaticListLookUpSettings instance to the parameter’s ValueSourceSettings property.

When you process report parameters with predefined static values in code, you may need to access the list of all parameter values. Refer to the LookUpHelper class description for details on how to complete this task.

Example

View Example: Create a Report Parameter with a List of Predefined Static Values

The following code sample demonstrates how to create a date-time parameter with a list of predefined dates:

using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.UI;
using System.Windows.Forms;
using System;
// ...
// Create a date-time parameter.
Parameter dateParameter = new Parameter();
dateParameter.Name = "dateParameter";
dateParameter.Description = "Date:";
dateParameter.Type = typeof(System.DateTime);

// Create a StaticListLookUpSettings instance and add predefined
// static values to the instance's LookUpValues collection.
StaticListLookUpSettings lookupSettings = new StaticListLookUpSettings();

lookupSettings.LookUpValues.Add(new LookUpValue
{
    Value = new DateTime(2014, 01, 01),
    Description = "January 1, 2014"
}
);

lookupSettings.LookUpValues.Add(new LookUpValue
{
    Value = new DateTime(2015, 02, 01),
    Description = "February 1, 2015"
}
);

lookupSettings.LookUpValues.Add(new LookUpValue
{
    Value = new DateTime(2016, 03, 01),
    Description = "March 1, 2016"
}
);

// Assign the specified settings to the parameter's ValueSourceSettings property.
dateParameter.ValueSourceSettings = lookupSettings;

// Create a report instance and add the parameter
// to the report's Parameters collection.
XtraReport1 report = new XtraReport1();
report.Parameters.Add(dateParameter);

// Use the created parameter to filter the report's data.
report.FilterString = "GetDate([OrderDate]) >= ?dateParameter";

Parameters in Expressions

When an expression is evaluated, it uses a parameter value (the Value property).

The GetDisplayText function in an expression allows you to obtain the descriptive name associated with a parameter: