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

Disable future dates on DateTimePicker Calender element

1 Answer 327 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Rajeev
Top achievements
Rank 1
Rajeev asked on 06 Aug 2008, 06:54 AM
Hi,

I have an urgent requirement from client in which we need to disable future dates on DateTimePicker Calender element. For Ex- if today's date is 6Aug., then all dates start from 7 Aug should be disabled (i.e All future dates should be shon diable), when user see calender element of DateTimePicker.

Please advice. Thanks in Advance

Rajeev Yadav

1 Answer, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 07 Aug 2008, 03:11 PM
Hello Rajeev,

Here is a sample code:

1. Subscibe to the opened event of radDatetimePicker:
  void Form1_Load(object sender, EventArgs e)
        {
            this.radDateTimePicker1.DateTimePickerElement.Opened +=new EventHandler(DateTimePickerElement_Opened);
        }


2. In the handler do the following:

        void DateTimePickerElement_Opened(object sender, EventArgs e)
        {
            CalendarTableElement table = ((this.radDateTimePicker1.DateTimePickerElement.GetCurrentBehavior() as RadDateTimePickerCalendar).Calendar.CalendarElement.CalendarVisualElement.Children[0].Children[1] as CalendarTableElement);
            foreach (CalendarCellElement cell in table.Children)
            {
                cell.Enabled = true;
                if (cell.Date > this.radDateTimePicker1.Value)
                {
                    cell.Enabled = false;
                }
            }
        }


I believe this helps.
Please contact me again if you need additional help.

Best wishes,
Boyko Markov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Rajeev
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Share this question
or