This is a migrated thread and some comments may be shown as answers.

DateTimePicker MinDate = MaxDate

2 Answers 470 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
LIMA Factory
Top achievements
Rank 1
LIMA Factory asked on 05 Dec 2016, 01:20 PM

Hello,

i use a DateTimePicker for my application to select a day. The selection is inside a very narrow time Intervall (1 - 3 Days). So i set the MinDate and MaxDate of the DateTimePicker accourdingly. When the Intervall is lager than 1 day the DateTimePicker works correctly. When the MinDate and the MaxDate is equal (only one day available, date cannot be changed) the display of the DateTimePicker is not correct:

Only the days before the actual date are grayed out.

It is possible to switch to different month / years (after teh actual date) with the build in functions.

Nevertheless is it not possible to select another day (which is good), but the user might get confused that his selection does not change the date.

Please confirm this behaviour and please provide a workaround for this behaviour.

Thank You.

Kind Regads

Ingo Müller

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Dec 2016, 09:31 AM
Hello Ingo,

Thank you for writing.  

I have logged it in our feedback portal and I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the RadDateTimePickerCalendar.Calendar.ElementRender event and disable the cells that are not in the applied interval: 

public RadForm1()
{
    InitializeComponent();
 
    this.radDateTimePicker1.MinDate = DateTime.Now;
    this.radDateTimePicker1.MaxDate = DateTime.Now;
 
    RadDateTimePickerCalendar calendarBehavior = this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar;
    calendarBehavior.Calendar.ElementRender += Calendar_ElementRender;
}
 
private void Calendar_ElementRender(object sender, RenderElementEventArgs e)
{
    if (e.Day.Date > this.radDateTimePicker1.MaxDate.Date || e.Day.Date < this.radDateTimePicker1.MinDate.Date)
    {
        e.Element.Enabled = false;
    }
    else
    {
        e.Element.Enabled = true;
    }
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
0
LIMA Factory
Top achievements
Rank 1
answered on 06 Dec 2016, 12:08 PM

Hello Dess,

thank You very much for Your Response and the Workaround!

It works perfectly!

Best Regards,

Ingo Müller

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
LIMA Factory
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
LIMA Factory
Top achievements
Rank 1
Share this question
or