Hi Ian,
You can restrict the available hours, by handling the ValueChanged event of the control. In the event handler, you can validate the selected value according to the day of the week and set different working hours. In order to update the element with the new
min and
max values, it will be also necessary to call its
PrepareContent method:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
var rdtpc =
this
.radDateTimePicker1.DateTimePickerElement.CurrentBehavior
as
RadDateTimePickerCalendar;
rdtpc.ShowTimePicker =
true
;
rdtpc.TimePicker.Culture =
new
System.Globalization.CultureInfo(
"DE-de"
);
rdtpc.TimePicker.TimePickerElement.InvalidateChildrenOnChildChanged =
true
;
this
.radDateTimePicker1.ValueChanged += RadDateTimePicker1_ValueChanged;
}
private
void
RadDateTimePicker1_ValueChanged(
object
sender, EventArgs e)
{
var rdtpc =
this
.radDateTimePicker1.DateTimePickerElement.CurrentBehavior
as
RadDateTimePickerCalendar;
DayOfWeek dayOfWeek =
this
.radDateTimePicker1.Value.Date.DayOfWeek;
switch
(dayOfWeek)
{
case
DayOfWeek.Sunday:
rdtpc.TimePicker.TimePickerElement.MinValue = DateTime.Today.Date.AddHours(12);
rdtpc.TimePicker.TimePickerElement.MaxValue = DateTime.Today.Date.AddHours(13);
break
;
case
DayOfWeek.Monday:
case
DayOfWeek.Tuesday:
case
DayOfWeek.Wednesday:
case
DayOfWeek.Thursday:
case
DayOfWeek.Friday:
rdtpc.TimePicker.TimePickerElement.MinValue = DateTime.Today.Date.AddHours(9);
rdtpc.TimePicker.TimePickerElement.MaxValue = DateTime.Today.Date.AddHours(17);
break
;
case
DayOfWeek.Saturday:
rdtpc.TimePicker.TimePickerElement.MinValue = DateTime.Today.Date.AddHours(10);
rdtpc.TimePicker.TimePickerElement.MaxValue = DateTime.Today.Date.AddHours(14);
break
;
}
rdtpc.TimePicker.TimePickerElement.PrepareContent();
}
}
I am also attaching a short video showing the result on my end.
Regards,
Hristo
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.