Back to Devexpress

RangeParameterEditorOptions.RegisterTimeRange(String, Func<TimeOnly>, Func<TimeOnly>, SvgImage) Method

corelibraries-devexpress-dot-xtrareports-dot-parameters-dot-rangeparametereditoroptions-dot-registertimerange-x28-string-func-timeonly-func-timeonly-svgimage-x29.md

latest5.6 KB
Original Source

RangeParameterEditorOptions.RegisterTimeRange(String, Func<TimeOnly>, Func<TimeOnly>, SvgImage) Method

Appends an item to the list of predefined time ranges with a custom icon.

Namespace : DevExpress.XtraReports.Parameters

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public static void RegisterTimeRange(
    string name,
    Func<TimeOnly> getStart,
    Func<TimeOnly> getEnd,
    SvgImage image
)
vb
Public Shared Sub RegisterTimeRange(
    name As String,
    getStart As Func(Of TimeOnly),
    getEnd As Func(Of TimeOnly),
    image As SvgImage
)

Parameters

NameTypeDescription
nameString

The predefined time range’s name.

| | getStart | Func<TimeOnly> |

The function that returns the predefined time range’s start time.

| | getEnd | Func<TimeOnly> |

The function that returns the predefined tim range’s end time.

| | image | SvgImage |

The SvgImage used as an icon for this time range in the time range parameter editor in Print Preview.

|

Remarks

Use this method to append an item to the list of predefined time ranges stored in the PredefinedTimeRanges property. The appended predefined time range becomes available in the time range parameter editor in Print Preview.

Example

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

See Also

Range Report Parameters

RegisterDateRange(String, Func<DateTime>, Func<DateTime>)

RangeParameterEditorOptions Class

RangeParameterEditorOptions Members

DevExpress.XtraReports.Parameters Namespace