Report Parameters with Predefined Static Values
- 3 minutes to read
You can create a parameter with a list of predefined values. In the Parameters panel, such a parameter allows users to select a value from the predefined list.
Design Time
Follow the steps below to create a parameter with a list of predefined static values in a Report Designer.
- Create a report parameter as described in the Create a Report Parameter topic.
Set the parameter’s Value Source (corresponds to the ValueSourceSettings property) to StaticListLookUpSettings. A grid appears in the Add New Parameter dialog where you can specify a static list of values.
Specify a list of values. Each value should have a description that is displayed in the Parameters Panel.
Runtime
Tip
Code example: How to assign multiple values to a report parameter.
To specify predefined static values for a parameter in code, create a StaticListLookUpSettings class instance and add static values to the StaticListLookUpSettings.LookUpValues collection. Assign the StaticListLookUpSettings instance to the parameter’s ValueSourceSettings property.
using DevExpress.XtraReports.Parameters;
using DevExpress.XtraReports.Expressions;
// ...
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 parameter's static list of predefined values
StaticListLookUpSettings lookupSettings = new StaticListLookUpSettings();
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,01,01), "January 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,02,01), "February 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,03,01), "March 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,04,01), "April 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,05,01), "May 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,06,01), "June 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,07,01), "July 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,08,01), "August 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,09,01), "September 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,10,01), "October 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,11,01), "November 1, 2019"));
lookupSettings.LookUpValues.Add(new LookUpValue(new DateTime(2019,12,01), "December 1, 2019"));
myDateParameter.ValueSourceSettings = lookupSettings;
report.Parameters.Add(myDateParameter);
// Filter report data by the specified parameter.
report.FilterString = "GetDate([OrderDate]) >= ?myDateParameter";