Skip to main content
A newer version of this page is available. .

Parameter Class

Provides functionality to a report parameter.

Namespace: DevExpress.XtraReports.Parameters

Assembly: DevExpress.Printing.v19.2.Core.dll

Declaration

public class Parameter :
    Component,
    IXtraSupportShouldSerialize,
    IXtraSupportDeserializeCollectionItem,
    IParameter,
    IFilterParameter,
    IMultiValueParameter,
    INullableParameter,
    IRangeRootParameter

Remarks

To maintain and store parameters, the XtraReport class implements the XtraReport.Parameters property, which holds a collection of Parameter objects. Each parameter is inherited from a Component, which means that you can control its accessibility in a report’s derivatives and outside the report class using the Modifiers and GenerateMember properties.

After you create a parameter, you can specify its value. The value type is defined by the Parameter.ParameterType property, which can be set to one of the enumerations values, each corresponding to a specific .NET type (e.g. String, Boolean, Int32).

Then, you can assign the value of the appropriate type to the Parameter.Value property. Note that if you leave this value empty at design time, this means that you either need to provide this value via code, or your end-users will be prompted to enter and submit parameter values.

Note

  • To refer to a parameter when using the mail merge or within a calculated field‘s expression, the parameter’s name should be specified after the question mark:

    ?Parameter_Name

  • Parameter names should not use dots and spaces.

See Using Report Parameters to learn more.

Example

This example demonstrates how to create a report with a parameter at runtime.

After a parameter is added to the report, its value can be used in the report’s XtraReportBase.FilterString, or displayed in a XRLabel control.

Then, when the report is being previewed, an end-user can modify the parameter’s value via the Parameters UI, which is enabled using the ReportPrintTool.AutoShowParametersPanel property.

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Parameters;
// ...

private void simpleButton1_Click(object sender, EventArgs e) {
    // Create a report instance.
    XtraReport1 report = new XtraReport1();

    // Create a parameter and specify its name.
    Parameter param1 = new Parameter();
    param1.Name = "CatID";

    // Specify other parameter properties.
    param1.Type = typeof(System.Int32);
    param1.Value = 1;
    param1.Description = "Category: ";
    param1.Visible = true;

    // Add the parameter to the report.
    report.Parameters.Add(param1);

    // Specify the report's filter string.
    report.FilterString = "[CategoryID] = [Parameters.CatID]";

    // Force the report creation without previously 
    // requesting the parameter value from end-users.
    report.RequestParameters = false;

    // Show the parameter's value on a Report Header band.
    XRLabel label = new XRLabel();
    label.DataBindings.Add(new XRBinding(param1, "Text", "Category: {0}"));
    ReportHeaderBand reportHeader = new ReportHeaderBand();
    reportHeader.Controls.Add(label);
    report.Bands.Add(reportHeader);

    // Assign the report to a ReportPrintTool,
    // to hide the Parameters panel,
    // and show the report's print preview.
    ReportPrintTool pt = new ReportPrintTool(report);
    pt.AutoShowParametersPanel = true;
    pt.ShowPreviewDialog();
}
See Also