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

Report Parameters with Predefined Dynamic Values

  • 3 minutes to read

You can create a parameter with a list of predefined values that are stored in a data source. In the Parameters panel, such a parameter allows users to select a value from the predefined list.

report-parameters-dynamic-values

Design Time

Follow the steps below to create a parameter with a list of predefined dynamic values in a Report Designer.

  1. Create a report parameter as described in the Create a Report Parameter topic.
  2. Set the parameter’s Value Source (corresponds to the ValueSourceSettings property) to DynamicListLookUpSettings. Additional fields appear in the Add New Parameter dialog where you can specify the storage that contains the list of predefined parameter values.

  3. Specify a Data Source, Data Adapter (for a DataSet only), and Data Member for the parameter values storage. Value Member defines a data field that fetches values to the parameter. Display Member defines a data field that stores values displayed in the Parameters panel.

    report-parameters-dynamic-values

    The specified data member’s value type should match the specified Parameter.Type.

    Use the Filter String property to filter parameter values or implement cascading parameters.

    Specify the Sort Order and Sort Member properties to sort parameter values in the Parameters panel’s editor.

Runtime

To specify predefined dynamic values for a parameter in code, create a DynamicListLookUpSettings class instance and use its properties to specify the storage of parameter values. Assign the DynamicListLookUpSettings instance to the parameter’s ValueSourceSettings property.

using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.Expressions;
// ...
DevExpress.DataAccess.ObjectBinding.ObjectDataSource objectDataSource = new DevExpress.DataAccess.ObjectBinding.ObjectDataSource() {
    Name = "ObjectDataSource1",
    DataSource = CreateLookups(),
};
public XtraReport CreateReportWithDateParameterDynamicList() {
    XtraReport1 report = new XtraReport1();

    Parameter myDateParameter = new Parameter();
    myDateParameter.Name = "myDateParameter";
    // Set the Visible property to true to request the parameter value from users.
    // Set this property to false to apply the parameter's value that is specified in code.
    myDateParameter.Visible = true;
    myDateParameter.Type = typeof(System.DateTime);
    // Specify the storage for the parameter's predefined values
    DynamicListLookUpSettings lookupSettings = new DynamicListLookUpSettings();
    lookupSettings.DataSource = objectDataSource;
    lookupSettings.ValueMember = "Value";
    lookupSettings.DisplayMember = "Description";
    myDateParameter.ValueSourceSettings = lookupSettings;
    report.Parameters.Add(myDateParameter);
    // Filter report data by the specified parameter.
    report.FilterString = "GetDate([OrderDate]) >= ?myDateParameter";

    return report;
}
static List<LookUpValue> CreateLookups() {
    return new List<LookUpValue>() {
        new LookUpValue(new DateTime(2019, 01, 01), "January 1, 2019"),
        new LookUpValue(new DateTime(2019, 02, 01), "February 1, 2019"),
    };
}