How to: Pass Parameters to a Report (Runtime Sample)

  • 2 minutes to read

This tutorial describes the process of creating a report parameter at runtime. It illustrates how to create a parameter and customize its options in code, and then use this parameter in the report's filter string, to filter the report's data based on the parameter value.

To create a parameter and define its options, handle the Load event of your Snap application's Main form.


using System;
using System.Windows.Forms;
using DevExpress.Snap;
using DevExpress.Snap.Core.API;
// ...

private void Form1_Load(object sender, EventArgs e) {
    Parameter param1 = new Parameter();
    param1.Name = "Region";
    param1.Type = typeof(System.String);
    param1.Value = "NEW ENGLAND";
    snapControl1.Document.Parameters.Add(param1);
}

When creating a parameter, make sure that its Type property is assigned properly, i.e., in strict correspondence to the value type provided by this parameter (e.g., a String type for string parameters).

NOTE

When changing the parameter's value, update all document fields by calling the FieldCollection.Update method.

After the parameter has been added to the Snap document's collection, you can use it in the report's FilterString editor expression.

The following image illustrates how you can filter your report to show only the data that corresponds to the specified parameter value.

snap-parameters-filter-string

To learn how to use parameters without writing any code, see How to: Pass Parameters to a Report.