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

Show week numbers in the month view

6 Answers 165 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Ana
Top achievements
Rank 1
Ana asked on 20 Jul 2011, 09:50 AM
Hello
I want know if i can or is possible show week numbers in the month view, specifically to the left corner cells.
Greetings

6 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 22 Jul 2011, 03:10 PM
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!

0
Ana
Top achievements
Rank 1
answered on 25 Jul 2011, 09:54 AM
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
0
Ivan Todorov
Telerik team
answered on 28 Jul 2011, 08:35 AM
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!

0
Peter
Top achievements
Rank 1
answered on 16 May 2013, 03:49 PM
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
0
Ivan Petrov
Telerik team
answered on 21 May 2013, 10:22 AM
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?
0
Peter
Top achievements
Rank 1
answered on 13 Jun 2013, 02:45 PM
Hi Ivan, 

this solved my Issue. Thank you very much. 

Best, 

Peter
Tags
Scheduler and Reminder
Asked by
Ana
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Ana
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or