Back to Devexpress

SchedulerControlPrintAdapter.DisplayTimeRegions Property

windowsforms-devexpress-dot-xtrascheduler-dot-reporting-dot-schedulercontrolprintadapter-319f7195.md

latest6.3 KB
Original Source

SchedulerControlPrintAdapter.DisplayTimeRegions Property

Gets or sets whether Scheduler Reports should display existing Time Regions.

Namespace : DevExpress.XtraScheduler.Reporting

Assembly : DevExpress.XtraScheduler.v25.2.Reporting.dll

NuGet Package : DevExpress.Win.SchedulerReporting

Declaration

csharp
[DefaultValue(true)]
public bool DisplayTimeRegions { get; set; }
vb
<DefaultValue(True)>
Public Property DisplayTimeRegions As Boolean

Property Value

TypeDefaultDescription
Booleantrue

true if Time Regions are visible; otherwise, false.

|

Remarks

TimeRegion objects allow you to create time intervals that impose specific restrictions on appointments. For instance, a Time Region can prevent users from adding new appointments to this interval, or modify appointments that already belong to it.

Time Regions have their own appearance so that users can identify them at runtime, but are hidden in Reports. Use the corresponding approach to display Time Regions based on whether you utilize the SchedulerControlPrintAdapter or SchedulerStoragePrintAdapter component to generate reports.

SchedulerControlPrintAdapter

A SchedulerControlPrintAdapter receives all data directly from the Scheduler Control, including Time Regions. To display them, enable the DisplayTimeRegions property.

csharp
buttonReport.Click += (s, e) => {
    var xr = new myXtraSchedulerReport();
    SchedulerControlPrintAdapter adp = new SchedulerControlPrintAdapter(schedulerControl1);
    adp.DisplayTimeRegions = true;
    xr.SchedulerAdapter = adp;
    var printTool = new DevExpress.XtraReports.UI.ReportPrintTool(xr);
    printTool.ShowPreview();
};
vb
AddHandler buttonReport.Click, Sub(s, e)
    Dim xr = New myXtraSchedulerReport()
    Dim adp As New SchedulerControlPrintAdapter(schedulerControl1)
    adp.DisplayTimeRegions = True
    xr.SchedulerAdapter = adp
    Dim printTool = New DevExpress.XtraReports.UI.ReportPrintTool(xr)
    printTool.ShowPreview()
End Sub

This approach does not allow you to choose which Time Regions should be visible.

SchedulerStoragePrintAdapter

A SchedulerStoragePrintAdapter receives data from a Scheduler Data Storage. Time Regions belong to a control itself and are not kept in the Storage. For this reason, the Adapter cannot access Time Regions and you need to populate the TimeRegions collection. This allows you to control which Time Regions should be visible in Reports.

csharp
buttonReport.Click += (s, e) => {
    var xr = new myXtraSchedulerReport();
    SchedulerStoragePrintAdapter adp = new SchedulerStoragePrintAdapter(schedulerStorage1);
    TimeRegion tr = new TimeRegion();
    tr.Start = baseDate.AddHours(6);
    tr.End = baseDate.AddHours(18);
    tr.Editable = true;
    tr.Recurrence = new RecurrenceInfo();
    tr.Recurrence.Start = tr.Start;
    tr.Recurrence.Type = RecurrenceType.Weekly;
    tr.Recurrence.WeekDays = WeekDays.WorkDays;
    adp.TimeRegions.Add(tr);
    xr.SchedulerAdapter = adp;
    var printTool = new DevExpress.XtraReports.UI.ReportPrintTool(xr);
    printTool.ShowPreview();
};
vb
AddHandler buttonReport.Click, Sub(s, e)
    Dim xr = New myXtraSchedulerReport()
    Dim adp As New SchedulerStoragePrintAdapter(schedulerStorage1)
    Dim tr As New TimeRegion()
    tr.Start = baseDate.AddHours(6)
    tr.End = baseDate.AddHours(18)
    tr.Editable = True
    tr.Recurrence = New RecurrenceInfo()
    tr.Recurrence.Start = tr.Start
    tr.Recurrence.Type = RecurrenceType.Weekly
    tr.Recurrence.WeekDays = WeekDays.WorkDays
    adp.TimeRegions.Add(tr)
    xr.SchedulerAdapter = adp
    Dim printTool = New DevExpress.XtraReports.UI.ReportPrintTool(xr)
    printTool.ShowPreview()
End Sub

Custom Draw Time Regions

Regardless of the adapter component type used, you can handle the TimeCellsControlBase.CustomDrawTimeRegion event to redraw Time Regions.

csharp
private void DvTimeCells_CustomDrawTimeRegion(object sender, CustomDrawTimeRegionEventArgs e) {
    DateTime baseDate = DateTimeHelper.GetStartOfWeek(DateTime.Today);
    baseDate = baseDate.AddDays(-15);
    if (e.TimeRegion.Start == baseDate.AddHours(6) && e.TimeRegion.End == baseDate.AddHours(18)) {
        e.Cache.FillRectangle(System.Drawing.Brushes.IndianRed, e.Bounds);
    }
}
vb
Private Sub DvTimeCells_CustomDrawTimeRegion(ByVal sender As Object, ByVal e As CustomDrawTimeRegionEventArgs)
    Dim baseDate As Date = DateTimeHelper.GetStartOfWeek(Date.Today)
    baseDate = baseDate.AddDays(-15)
    If e.TimeRegion.Start = baseDate.AddHours(6) AndAlso e.TimeRegion.End = baseDate.AddHours(18) Then
        e.Cache.FillRectangle(System.Drawing.Brushes.IndianRed, e.Bounds)
    End If
End Sub

See Also

SchedulerControlPrintAdapter Class

SchedulerControlPrintAdapter Members

DevExpress.XtraScheduler.Reporting Namespace