Back to Devexpress

Report Parameters with Predefined Dynamic Values

xtrareports-401662-feature-guide-to-devexpress-reports-use-report-parameters-report-parameters-with-predefined-dynamic-values.md

latest9.2 KB
Original Source

Report Parameters with Predefined Dynamic Values

  • Feb 18, 2026
  • 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 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.

  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.

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.

csharp
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);
vb
Imports DevExpress.DataAccess.ObjectBinding
Imports DevExpress.XtraReports.Parameters
Imports Parameter = DevExpress.XtraReports.Parameters.Parameter
Imports System.Windows.Forms
Imports System
' ...
' Create and set up an Object data source.
Private objectDataSource = New ObjectDataSource()
objectDataSource.Name = "Employees"
objectDataSource.DataSource = GetType(EmployeeDataSource)
objectDataSource.DataMember = "GetEmployeeList"
objectDataSource.Constructor = New ObjectConstructorInfo()
objectDataSource.Fill()

' Create a report parameter.
Dim param As New Parameter()
param.Name = "employeePosition"
param.Description = "Employee position:"
param.Type = GetType(String)

' Create a DynamicListLookUpSettings instance and
' set up its properties.
Dim 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.
Dim report = New XtraReport1()
report.Parameters.Add(param)

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

csharp
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;
    }
}
vb
Imports System.Collections.Generic
' ...
Public Class Employee
    Public Property Name() As String
    Public Property Position() As String
End Class

Public Class EmployeeDataSource
    Private employees As New List(Of Employee)() From {
        New Employee() With {
            .Name = "Antonio Moreno",
            .Position = "CEO"
        },
        New Employee() With {
            .Name = "Thomas Hardy",
            .Position = "Sales Representative"
        },
        New Employee() With {
            .Name = "Christina Berglund",
            .Position = "Order Administrator"
        },
        New Employee() With {
            .Name = "Frédérique Citeaux",
            .Position = "Marketing Manager"
        },
        New Employee() With {
            .Name = "Hanna Moos",
            .Position = "Software Developer"
        }
    }

    Public Iterator Function GetEmployeeList() As IEnumerable(Of Employee)
        For Each employee In employees
            Yield employee
        Next employee
    End Function
End Class

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: