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

Rad calendar multiview. Hide months views greater than RangeMaxDate

1 Answer 92 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 31 May 2011, 10:28 AM
Hi all,

I`m using rad calendar with multiview (1 row 4 columns). RangeMinDate is set to 01.01.CurrentYear-1 and RangeMaxDate is set to 31.12.CurrentYear+2.
When I`m navigating to the last allowed month it is also visible 3 month from year 2014.
I would like those not allowed months (greater than  RangeMaxDate ) not to be displayed at all, or, if it is possible always display the last month in the range as the last (4th) month in the view, not the first one.
See attached pictures.
Also I wonder is it possible to change in runtime the backcolor and fore color of the selected dates.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 01 Jun 2011, 03:39 PM
Hello Pavel,

Thank you for contacting us.

You can achieve the desired behavior by subscribing to the ViewChanged event and handling it the following way:
private void radCalendar2_ViewChanged(object sender, EventArgs e)
{
    MultiMonthViewElement viewElement = (this.radCalendar2.CalendarElement.CalendarVisualElement as MultiMonthViewElement);
    if(viewElement == null)
        return;
 
    foreach(RadElement element in viewElement.GetMultiTableElement().Children)
    {
        MonthViewElement monthElement = element as MonthViewElement;
        if(monthElement != null)
        {
            if (monthElement.TableElement.View.ViewStartDate > this.radCalendar2.RangeMaxDate)
                monthElement.Visibility = ElementVisibility.Hidden;
            else
                monthElement.Visibility = ElementVisibility.Visible;
        }   
    }
}

As to your second question, you can change the color of the selected cell at runtime by subscribing to the SelectionChanged event as it is shown in the next code snippet:
private void radCalendar2_ElementRender(object sender, RenderElementEventArgs e)
{
    e.Element.ResetValue(LightVisualElement.ForeColorProperty);
    e.Element.ResetValue(LightVisualElement.BackColorProperty);
    e.Element.ResetValue(LightVisualElement.BackColor2Property);
    e.Element.ResetValue(LightVisualElement.BackColor3Property);
    e.Element.ResetValue(LightVisualElement.BackColor4Property);
}
 
private void radCalendar2_SelectionChanged(object sender, EventArgs e)
{
    MultiMonthViewElement viewElement = (this.radCalendar2.CalendarElement.CalendarVisualElement as MultiMonthViewElement);
    foreach (MonthViewElement monthElement in viewElement.GetMultiTableElement().Children)
    {
        CalendarCellElement cell = monthElement.TableElement.GetCellByDate(this.radCalendar2.SelectedDate);
        if (cell != null)
        {
            cell.ForeColor = Color.White;
            cell.BackColor = Color.Red;
            cell.BackColor2 = Color.Red;
            cell.BackColor3 = Color.Red;
            cell.BackColor4 = Color.Red;
        }
    }
}

Note that you should also subscribe to the ElementRender and reset the properties you have set, because RadCalendars visual items are reused.

I hope this helps. If you have any other questions, do not hesitate to ask.

Kind regards,
Ivan Todorov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Pavel
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or