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.