Completed
Last Updated: 23 Feb 2021 08:57 by ADMIN
Release R1 2021 SP2
Treesa
Created on: 25 Jan 2021 14:16
Category: Calendar
Type: Bug Report
0
RadCalendar: When the date is set to DateTime.MaxValue and the user tries to show the navigation pop-up an exception is thrown.

To reproduce: 
1. Add RadCalendar/or RadDateTimePicker/ and the MaxValue of calendar control to DateTime.MaxValue.
2. Click on the header and an exception is thrown: System.ArgumentOutOfRangeException: 'The added or subtracted value results in an un-representable DateTime.
Parameter name: months'

public RadForm1()
{
    InitializeComponent();

    RadDateTimePickerElement.MaximumDateTime = DateTime.MaxValue;
    this.radDateTimePicker1.MaxDate = DateTime.MaxValue;
    this.radDateTimePicker1.Value = this.radDateTimePicker1.MaxDate;
    RadDateTimePickerCalendar calendarBehavior = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
    calendarBehavior.Calendar.RangeMaxDate = this.radDateTimePicker1.MaxDate;
}

 

Workaround:
To work around this issue we can stop showing this pop-up when one of the three last months of the MaxDate.Year is selected in the RadCalendar ViewChanged event:

private void Calendar_ViewChanged(object sender, EventArgs e)
{
    RadDateTimePickerCalendar calendarBehavior = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
    DateTime calendarDate = calendarBehavior.Calendar.CalendarElement.View.ViewStartDate;
    if (calendarDate.Year == this.radDateTimePicker1.MaxDate.Year &&
        calendarDate.Month >= 10)
    {
        calendarBehavior.Calendar.HeaderNavigationMode = HeaderNavigationMode.None;
    }
    else
    {
        calendarBehavior.Calendar.HeaderNavigationMode = HeaderNavigationMode.Popup;
    }
}

0 comments