Back to Devexpress

RangeParameterEditorOptions Class

corelibraries-devexpress-dot-xtrareports-dot-parameters-58abaf4f.md

latest8.0 KB
Original Source

RangeParameterEditorOptions Class

A static class that provides access to the list of predefined ranges that are displayed in the date or time range parameter‘s editor in Print Preview.

Namespace : DevExpress.XtraReports.Parameters

Assembly : DevExpress.Printing.v25.2.Core.dll

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public static class RangeParameterEditorOptions
vb
Public Module RangeParameterEditorOptions

Remarks

Date and time range parameters are used in reporting applications.

A range parameter editor displays a list of predefined ranges that users can select from:

Predefined ranges for “Date” and “Date and Time” range parameters Predefined ranges for “Time” range parameters

Use the RangeParameterEditorOptions static class in WinForms and WPF applications to customize the list of predefined value ranges. The following members allow you to adjust the predefined ranges:

PredefinedDateRangesStores the list of predefined date ranges available in the date range parameter editor in Print Preview.RegisterDateRange(String, Func<DateTime>, Func<DateTime>)Appends an item to the list of predefined date ranges.PredefinedTimeRangesStores the list of predefined time ranges available in the time range parameter editor in Print Preview.RegisterTimeRange(String, Func<TimeOnly>, Func<TimeOnly>)Appends an item to the list of predefined time ranges with a default icon.RegisterTimeRange(String, Func<TimeOnly>, Func<TimeOnly>, SvgImage)Appends an item to the list of predefined time ranges with a custom icon.

Examples

The following example modifies the available date ranges displayed in Print Preview. The code clears the list of predefined date ranges and adds the September and October predefined ranges to the parameter’s editor for a date range parameter:

Note

This code is in effect for WinForms and WPF End-User Reporting Applications only.

csharp
using DevExpress.XtraReports.Parameters;
// ...
// Remove all predefined ranges and add two new date ranges.
RangeParameterEditorOptions.PredefinedDateRanges.Clear();
RangeParameterEditorOptions.RegisterDateRange("September", () => new DateTime(2019,9,1), () => new DateTime(2019,9,30));
RangeParameterEditorOptions.RegisterDateRange("October", () => new DateTime(2019,10,1), () => new DateTime(2019,10,31));
vb
Imports DevExpress.XtraReports.Parameters
' ...
' Remove all predefined ranges and add two new date ranges.
RangeParameterEditorOptions.PredefinedDateRanges.Clear()
RangeParameterEditorOptions.RegisterDateRange("September", Function() New Date(2019,9,1), Function() New Date(2019,9,30))
RangeParameterEditorOptions.RegisterDateRange("October", Function() New Date(2019,10,1), Function() New Date(2019,10,31))

Refer to the following example that creates a date range parameter in code and uses this parameter to filter the report’s data:

View Example: Create a Date-Range Report Parameter

The following example modifies the available time ranges displayed in Print Preview. The code adds the NightShift and Last Two Hours predefined ranges to the parameter’s editor for a time range parameter:

Note

This code is in effect for WinForms and WPF End-User Reporting Applications only.

csharp
using DevExpress.XtraReports.Parameters;
// ...
// Uncomment the line below if you want to clear the collection before adding new time ranges:
//RangeParameterEditorOptions.PredefinedTimeRanges.Clear();
string timeRangeNightShift = "Night Shift";
if (!RangeParameterEditorOptions.PredefinedTimeRanges.ContainsKey(timeRangeNightShift)) {
    RangeParameterEditorOptions.RegisterTimeRange(timeRangeNightShift,() => new TimeOnly(23,0),() => new TimeOnly(5,0),SvgImage.FromFile("time.svg"));
}
string timeRangeLastTwoHours = "Last Two Hours";
if (!RangeParameterEditorOptions.PredefinedTimeRanges.ContainsKey(timeRangeLastTwoHours)) {
    TimeOnly previousHour = TimeOnly.FromDateTime(DateTime.Now.AddHours(-2));
    TimeOnly currentHour = TimeOnly.FromDateTime(DateTime.Now.AddHours(0));
    RangeParameterEditorOptions.RegisterTimeRange(timeRangeLastTwoHours, () => previousHour,() => currentHour);
}
vb
Imports DevExpress.XtraReports.Parameters
Imports DevExpress.XtraReports.Expressions
' ...
' Uncomment the line below if you want to clear the collection before adding new time ranges:
' RangeParameterEditorOptions.PredefinedTimeRanges.Clear()
Dim timeRangeNightShift As String = "Night Shift"
If Not RangeParameterEditorOptions.PredefinedTimeRanges.ContainsKey(timeRangeNightShift) Then
    RangeParameterEditorOptions.RegisterTimeRange(timeRangeNightShift, Function() New TimeOnly(23, 0), Function() New TimeOnly(5, 0), SvgImage.FromFile("time.svg"))
End If

Dim timeRangeLastTwoHours As String = "Last Two Hours"
If Not RangeParameterEditorOptions.PredefinedTimeRanges.ContainsKey(timeRangeLastTwoHours) Then
    Dim previousHour As TimeOnly = TimeOnly.FromDateTime(DateTime.Now.AddHours(-2))
    Dim currentHour As TimeOnly = TimeOnly.FromDateTime(DateTime.Now.AddHours(0))
    RangeParameterEditorOptions.RegisterTimeRange(timeRangeLastTwoHours, Function() previousHour, Function() currentHour)
End If

Inheritance

Object RangeParameterEditorOptions

See Also

RangeParameterEditorOptions Members

Range Report Parameters

DevExpress.XtraReports.Parameters Namespace