Show week numbers in the month view

7 posts, 0 answers
  1. Ana
    Ana avatar
    5 posts
    Member since:
    Jun 2011

    Posted 20 Jul 2011 Link to this post

    Hello
    I want know if i can or is possible show week numbers in the month view, specifically to the left corner cells.
    Greetings
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 22 Jul 2011 Link to this post

    Hi Ana,

    Thank you for your question.

    Yes, this can be achieved by inheriting from RadScheduler and changing the text of the left header cells as it is shown in the following code snippet:
    public class MyScheduler : RadScheduler
    {
        public static int GetWeekNumber(DateTime dtPassed)
        {
            CultureInfo ciCurr = CultureInfo.CurrentCulture;
     
            int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
     
            return weekNum;
        }
     
        public override void InvalidateElement(Telerik.WinControls.RadElement element)
        {
            if (this.ActiveViewType == SchedulerViewType.Month)
            {
                foreach (RadElement child in (this.SchedulerElement.ViewElement as SchedulerMonthViewElement).VerticalHeader.Children)
                {
                    SchedulerHeaderCellElement cell = (child as SchedulerHeaderCellElement);
                    if (cell != null)
                    {
                        cell.Text = GetWeekNumber(cell.Date).ToString();
                    }
                }
            }
     
            base.InvalidateElement(element);
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadScheduler).FullName;
            }
            set
            {
                base.ThemeClassName = value;
            }
        }
    }

    You should also replace all your RadScheduler instances with MyScheduler ones in order to get this working.

    I hope you find this useful. Feel free to ask if you have any further questions.

    Greetings,
    Ivan Todorov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ana
    Ana avatar
    5 posts
    Member since:
    Jun 2011

    Posted 25 Jul 2011 Link to this post

    Hi Ivan Todorov

    I apply the code that you give me, but i found a error when i apply the code ( as shown in the image that will attached ).
    Can you help me ?

    Greetings
  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 Jul 2011 Link to this post

    Hello Ana,

    The most probable reason for this error is the usage of a grouping by resource. In this case, you should use the following InvalidateElement function which covers both scenarios:
    public override void InvalidateElement(Telerik.WinControls.RadElement element)
    {
        if (this.ActiveViewType == SchedulerViewType.Month)
        {
            if (this.GroupType == Telerik.WinControls.UI.GroupType.Resource)
            {
                foreach (SchedulerMonthViewElement viewElement in
                       (this.SchedulerElement.ViewElement as SchedulerMonthViewGroupedByResourceElement).GetMonthViewElements())
                    foreach (RadElement child in viewElement.VerticalHeader.Children)
                    {
                        SchedulerHeaderCellElement cell = (child as SchedulerHeaderCellElement);
                        if (cell != null)
                        {
                            cell.Text = GetWeekNumber(cell.Date).ToString();
                        }
                    }
            }
            else
            {
                if (this.ActiveViewType == SchedulerViewType.Month)
                {
                    foreach (RadElement child in (this.SchedulerElement.ViewElement as SchedulerMonthViewElement).VerticalHeader.Children)
                    {
                        SchedulerHeaderCellElement cell = (child as SchedulerHeaderCellElement);
                        if (cell != null)
                        {
                            cell.Text = GetWeekNumber(cell.Date).ToString();
                        }
                    }
                }
            }
        }
     
        base.InvalidateElement(element);
    }

    I hope this is useful. If you are still experiencing problems, you can open a support ticket and send us your project. This will help us investigate the complete scenario and provide you with more accurate answers.

    Kind regards,
    Ivan Todorov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Peter
    Peter avatar
    16 posts
    Member since:
    Apr 2012

    Posted 16 May 2013 Link to this post

    Hi,

    the override of the method InvalidateElement(Telerik.WinControls.RadElement) is not possible because it is not present anymore. How can I achieve the same behaviour with todays releases?

    Thank you in advance for your answer.

    Best,

    Peter
  7. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 21 May 2013 Link to this post

    Hi Peter,

    Thank you for writing.

    You can use the ElementInvalidated event to achieve the same result with the new version. Here is a code example:
    this.radScheduler1.ElementInvalidated += radScheduler1_ElementInvalidated;
     
    private void radScheduler1_ElementInvalidated(object sender, EventArgs e)
    {
        SchedulerHeaderCellElement cell = sender as SchedulerHeaderCellElement;
     
        if (cell != null && cell.Parent is MonthViewVerticalHeader)
        {
            cell.Text = "Week# " + GetWeekNumber(cell.Date).ToString();
        }
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Ivan Petrov
    the Telerik team
    RadChart for WinForms is obsolete. Now what?
  8. Peter
    Peter avatar
    16 posts
    Member since:
    Apr 2012

    Posted 13 Jun 2013 Link to this post

    Hi Ivan, 

    this solved my Issue. Thank you very much. 

    Best, 

    Peter
Back to Top
UI for WinForms is Visual Studio 2017 Ready