Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Calendar and DateTimePicker, TimePicker and Clock > Restricted date selection in RadTimePicker

Not answered Restricted date selection in RadTimePicker

Feed from this thread
  • Jeff Barnd avatar

    Posted on Jan 27, 2009 (permalink)

    Hello,
    I'm working with the RadCalendar control in both the Winform environment.  We need to restrict the dates that can be selected in the RadTimePicker control to a specific list of dates.  We also need to highlight the dates that can be selected.  A different background color on these dates would help the users pick a allowed date.  We also need to restrict the user from selecting dates that are not on the allowed list of dates.

    Is there a way to do this?

    Thank you in advance for the feedback and guidance!

    Your help is much appreciated,
    Jeff-

    Reply

  • Boyko Markov Boyko Markov admin's avatar

    Posted on Feb 2, 2009 (permalink)

    Hi Jeff Barnd,

    I have a solution for the scenario you have. Here it is:

    1. Create a list with the dates you can select.
      List<DateTime> dates = new List<DateTime>();
    2. Subscribe to SelectionChanging, ElementRender and MouseUp of RadCalendar
    3. In the selection changing handler I restrict the selection doing the following:
     void radCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
            {
                Point pt = this.radCalendar1.PointToClient(Cursor.Position);
                foreach (CalendarCellElement cell in (this.radCalendar1.CalendarElement.CalendarVisualElement as MonthViewElement).TableElement.Children)
                {
                    if (cell.HitTest(pt))
                    {
                        if (!this.dates.Contains(cell.Date))
                        {
                            e.Cancel = true;
                            this.radCalendar1.InvalidateCalendar();
                        }
                        break;
                    }
                }
            }
    4. In the ElementRender handler I color the cells which I can select.
     void radCalendar1_ElementRender(object sender, RenderElementEventArgs e)
            {
                if (this.dates.Contains(e.Day.Date))
                {
                    e.Element.DrawFill = true;
                    e.Element.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                    e.Element.BackColor = Color.Red;
                }
                else
                    e.Element.DrawFill = false;
            }
    5. In the MouseUp handler I clear the visual appearance of the focused and selected cells
     Point pt = this.radCalendar1.PointToClient(Cursor.Position);

                foreach (CalendarCellElement cell in (this.radCalendar1.CalendarElement.CalendarVisualElement as MonthViewElement).TableElement.Children)
                {
                    if (cell.HitTest(pt))
                    {
                        if (!this.dates.Contains(cell.Date))
                        {
                            cell.Focused = false;
                            cell.Selected = false;
                        }
                        break;
                    }
                }


    I hope this helps,

    Best wishes,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Calendar and DateTimePicker, TimePicker and Clock > Restricted date selection in RadTimePicker
Related resources for "Restricted date selection in RadTimePicker"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]