Back to Devexpress

How to: Display Custom Day Headers

windowsforms-4819-controls-and-libraries-scheduler-examples-appearance-how-to-display-custom-day-headers.md

latest2.7 KB
Original Source

How to: Display Custom Day Headers

  • Sep 07, 2023
  • 2 minutes to read

This document illustrates the use of HeaderCaptionService to change the display format of a Day View column header.

To accomplish this, substitute the service with a custom service which contains method overrides. The list of methods which can be overridden is found in the Formatting Services topic.

The following code implements a descendant class which displays a New Year’s greeting in the day header:

csharp
public class CustomHeaderCaptionService : HeaderCaptionServiceWrapper {
    public CustomHeaderCaptionService(IHeaderCaptionService service) : base(service) {
    }
    #region IHeaderCaptionService Members
    public override string GetDayColumnHeaderCaption(DayHeader header) {
        DateTime date = header.Interval.Start.Date;
        if (date.Month == 1 && date.Day == 1)
            return "{0:yyyy} Happy New Year!";
        else
            return base.GetDayColumnHeaderCaption(header);
    }
    #endregion
}
vb
Public Class CustomHeaderCaptionService
    Inherits HeaderCaptionServiceWrapper
    Public Sub New(ByVal service As IHeaderCaptionService)
        MyBase.New(service)
    End Sub
    #Region "IHeaderCaptionService Members"
    Public Overrides Function GetDayColumnHeaderCaption(ByVal header As DayHeader) As String
        Dim [date] As DateTime = header.Interval.Start.Date
        If [date].Month = 1 AndAlso [date].Day = 1 Then
            Return "{0:yyyy} Happy New Year!"
        Else
            Return MyBase.GetDayColumnHeaderCaption(header)
        End If
    End Function
    #End Region
End Class

You should create a service and substitute a default service with a custom one. The technique is identical to that demonstrated in the How to: Display TimeRulers with Different Time Formats Together article.

Tip

A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/e507/winforms-scheduler-formatting-services.

See Also

Services

How to: Display TimeRulers with Different Time Formats Together