Rad calendar multiview. Hide months views greater than RangeMaxDate

2 posts, 1 answers
  1. Pavel
    Pavel avatar
    1 posts
    Member since:
    Sep 2010

    Posted 31 May 2011 Link to this post

    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.

  2. Answer
    Ivan Todorov
    Ivan Todorov avatar
    688 posts

    Posted 01 Jun 2011 Link to this post

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