Skip to main content

Report Parameters with Predefined Dynamic Values

  • 5 minutes to read

You can create a report parameter that uses a list of values from a data source. 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 dynamic values

Create a List of Predefined Values in the Report Designer

Follow the steps below to create a parameter with a list of dynamic 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 DynamicListLookUpSettings. Additional fields appear in the Add New Parameter dialog and allow you to specify a data source for parameter values.

    Specify dynamic values for a report parameter

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

    Specify parameter options for a parameter with dynamic values

    Note

    The 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.

Create a List of Predefined Values in Code

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

If you open a report that contains parameters with predefined dynamic values in the Web End-User Report Designer, ensure that a data source used to supply parameter values is serializable. If the data source is not serializable, its data is lost and not displayed in the End-User Report Designer. The same applies to reports loaded into the Web Document Viewer from a Report Storage. Refer to the following topic for details on data source serialization: Serialize Data Sources.

When you process report parameters with predefined dynamic 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 Dynamic Values

The following example demonstrates how to create a report parameter with a list of dynamic values loaded from an Object Data Source.

using DevExpress.DataAccess.ObjectBinding;
using DevExpress.XtraReports.Parameters;
using Parameter = DevExpress.XtraReports.Parameters.Parameter;
using System.Windows.Forms;
using System;
// ...
// Create and set up an Object data source.
var objectDataSource = new ObjectDataSource();
objectDataSource.Name = "Employees";
objectDataSource.DataSource = typeof(EmployeeDataSource);
objectDataSource.DataMember = "GetEmployeeList";
objectDataSource.Constructor = new ObjectConstructorInfo();
objectDataSource.Fill();

// Create a report parameter.
Parameter param = new Parameter();
param.Name = "employeePosition";
param.Description = "Employee position:";
param.Type = typeof(string);

// Create a DynamicListLookUpSettings instance and
// set up its properties.
var lookupSettings = new DynamicListLookUpSettings();
lookupSettings.DataSource = objectDataSource;
lookupSettings.ValueMember = "Name";
lookupSettings.DisplayMember = "Position";

// Assign data storage settings to the parameter's ValueSourceSettings property.
param.ValueSourceSettings = lookupSettings;

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

The example above uses the following Object data source to supply dynamic values for the report parameter:

using System.Collections.Generic;
// ...
public class Employee {
    public string Name { get; set; }
    public string Position { get; set; }
}

public class EmployeeDataSource {
    private List<Employee> employees = new List<Employee>() {
        new Employee() {
            Name = "Antonio Moreno",
            Position = "CEO"
        },
        new Employee() {
            Name = "Thomas Hardy",
            Position = "Sales Representative"
        },
        new Employee() {
            Name = "Christina Berglund",
            Position = "Order Administrator"
        },
        new Employee() {
            Name = "Frédérique Citeaux",
            Position = "Marketing Manager"
        },
        new Employee() {
            Name = "Hanna Moos",
            Position = "Software Developer"
        }
    };

    public IEnumerable<Employee> GetEmployeeList() {
        foreach (var employee in employees)
            yield return employee;
    }
}

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 display name associated with a parameter:

Parameter with Dynamic List - GetDisplayText Function