Hello Chloe,
The behavior you observe is expected and is by design as once a selection is made on either the date or time part of the picker, the following code is executed:
You can observe that if the
SelectedDate is
null, the current date will be used.
To achieve the desired result, you can handle the
SelectionChanged event of the control in the following manner:
private
void
RadDateTimePicker_SelectionChanged(
object
sender, SelectionChangedEventArgs e)
{
var picker = sender
as
RadDateTimePicker;
var newDate = e.AddedItems[0]
as
DateTime?;
var isValidDate = picker.SelectableDateStart <= newDate && newDate <= picker.SelectableDateEnd;
if
(!isValidDate)
{
if
(newDate < picker.SelectableDateStart)
{
var year = picker.SelectableDateStart.Value.Year;
var month = picker.SelectableDateStart.Value.Month;
var day = picker.SelectableDateStart.Value.Day;
var hour = newDate.Value.Hour;
var minute = newDate.Value.Minute;
var second = newDate.Value.Second;
picker.SelectedValue =
new
DateTime(year, month, day, hour, minute, second);
}
else
if
(newDate > picker.SelectableDateEnd)
{
var year = picker.SelectableDateEnd.Value.Year;
var month = picker.SelectableDateEnd.Value.Month;
var day = picker.SelectableDateEnd.Value.Day;
var hour = newDate.Value.Hour;
var minute = newDate.Value.Minute;
var second = newDate.Value.Second;
picker.SelectedValue =
new
DateTime(year, month, day, hour, minute, second);
}
}
}
Please let me know whether such an approach would work for you.
Regards,
Dilyan Traykov
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.