Skip to main content
A newer version of this page is available. .

How to: Modify Date Formatting of Headers in the XtraScheduler Report

  • 2 minutes to read

This document illustrates how the Scheduler services can be used in Scheduler Reporting to modify captions of the view elements. In other words, the default HeaderCaptionService is substituted to change the date formatting used by the HorizontalDateHeaders in the daily style report.

Note

You can handle the HorizontalDateHeaders.CustomDrawDayHeader event to accomplish manual painting of the header.

using DevExpress.XtraScheduler.Reporting;
using DevExpress.XtraScheduler.Services;
using DevExpress.XtraScheduler.Drawing;
using DevExpress.XtraScheduler.Services.Implementation;
// ...
    string dateFormat = "dd-MMM, ddd";
    SchedulerStoragePrintAdapter storagePrintAdapter = 
        XtraSchedulerReport1.SchedulerAdapter as SchedulerStoragePrintAdapter;
    if (storagePrintAdapter != null) {
        storagePrintAdapter.RemoveService(typeof(IHeaderCaptionService));
        IHeaderCaptionService customHeaderCaptionService = 
            new CustomHeaderCaptionService(dateFormat);
        storagePrintAdapter.AddService(typeof(IHeaderCaptionService), 
            customHeaderCaptionService);
    }

public class CustomHeaderCaptionService : HeaderCaptionServiceWrapper {
    string format;
    public CustomHeaderCaptionService(string format)
        : base(new HeaderCaptionService()) {
        this.format = format;
    }
    protected virtual string CreateFormat(string format) {
        if(format == "Default")
            return string.Empty;
        return String.Format("{{0:{0}}}", format);
    }
    public override string GetDayColumnHeaderCaption(DayHeader header) {
        return CreateFormat(format);
    }
}
See Also