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;
}
}