Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1600
How to Format MonthHeaderCaption of UltraCalendarCombo
posted

Hello, I was strugling to find out the way to set the format of MonthHeaderCaption of UltraCalendarCombo.

Currently it displays a format like January 2008, February 2008,... and so on.

How can I change the format of this to something like 1/2008, 2/2008, ... or Jan 2008, Feb 2008, ..... or January, February, ......?

Of course, it was easy to set the format of textbox by setting

UltraCalendarCombo1.Format = "MMMM dd"

However, I could not find any method to set the format of MonthHeader.

 

Parents
  • 69832
    Offline posted

    The control does not extend a way to customize the format of the header text because it displays the name of the month, whereas the format for the edit portion is applied to a specific date. By default, we obtain the names of the month from the current culture's DateTimeFormatInfo. The UltraCalendarInfo.DaysOfWeek collection provides a way to override the display names of each month (see LongDescription/ShortDescription properties of the DayOfWeek object).

    The following code sample demonstrates how to solve the problem you describe here using the IUIElementCreationFilter interface:

    using Infragistics.Win.UltraWinSchedule;
    using Infragistics.Win.UltraWinSchedule.MonthViewMulti;

    /// <summary>
    /// Implements IUIElementCreationFilter for the purpose of customizing
    /// the header text for the UltraMonthViewMulti control.
    /// </summary>
    public class MonthHeaderCreationFilter : IUIElementCreationFilter
    {
        #region IUIElementCreationFilter Members

        void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
        {
            MonthHeaderAreaUIElement headerElement = parent as MonthHeaderAreaUIElement;
            if ( headerElement != null )
            {
                TextUIElement textElement = headerElement.GetDescendant( typeof(TextUIElement) ) as TextUIElement;
                if ( textElement != null )
                {
                    Month month = headerElement.GetContext( typeof(Month) ) as Month;
                    if ( month != null )
                    {
                        textElement.Text = string.Format( "{0}/{1}", month.MonthNumber, month.Year.YearNumber );
                    }
                }
            }
        }

        bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
        {
            return false;
        }

        #endregion
    }

Reply Children
No Data