Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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