Disable future dates on DateTimePicker Calender element

2 posts, 0 answers
  1. Rajeev
    Rajeev avatar
    10 posts
    Member since:
    Apr 2008

    Posted 06 Aug 2008 Link to this post


    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
  2. Boyko Markov
    Boyko Markov avatar
    610 posts

    Posted 07 Aug 2008 Link to this post

    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.
Back to Top