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

Calendar WeekNummering

4 Answers 217 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
A. Drost
Top achievements
Rank 1
A. Drost asked on 14 Mar 2014, 10:39 AM
Good day Telerik Forums


i have a question relating the RadCalendar control.

for an application i am developing we needed to display Week numbers.
so after switching on Row headers in RadCalendar, we found out that the numbering does not correspond with our previous controls.


Is there a way to alter the numbering of weeks?
changing culture did not have (any) desired effect.


i have included a picture displaying the differences.
on a side note: in telerik weeks go almost always to 53(sometimes to 54) and always start at 2 unless the year starts on a monday.


thanks in advance and with kind regards!
A. Drost

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Mar 2014, 10:13 AM
Hello,

Thank you for writing.

Our RadCalendar uses the standard CalendarWeekRule to determine the first week of the year. By default its value is FirstDay. It is possible to change it as follows in order to customize the week number calculation: 
public Form1()
{
    InitializeComponent();
 
    radCalendar1.AllowMultipleView = true;
    radCalendar1.MultiViewColumns = 1;
    radCalendar1.MultiViewRows = 5;
    radCalendar1.ShowRowHeaders = true;
     
    CultureInfo ci = new CultureInfo("en-US");
    CalendarWeekRule weekRule = CalendarWeekRule.FirstFullWeek;
    ci.DateTimeFormat.CalendarWeekRule = weekRule;
    radCalendar1.Culture = ci;
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
0
A. Drost
Top achievements
Rank 1
answered on 21 Mar 2014, 08:58 AM
Good day Desislava

Thanks for the reply, it has pointed me in the right direction.

but even after adding your suggested change i keep having week numbering issues.
the numbers just don't match with the desired effect.

i have added a picture for a clearer explanation.

thanks in advance for your time!


with kind regards,
A.Drost
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Mar 2014, 08:40 AM
Hello,

Thank you for getting back to me.

I have made several tests. However, when the CultureInfo.DateTimeFormat.CalendarWeekRule is FirstDay, it indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week. As a result 01/01/2014 should be displayed as week 1 and 31/12/2013 as week 53.
I confirm that it is an issue with our RadCalendar's week numbering. I have logged it in our Feedback Portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - Feedback Item.

I have also updated your 
Telerik points.

Currently, due to the specificity of the RadCalendar, the suitable workaround that I can suggest is to use the ViewChanged event as follows:
private void radCalendar1_ViewChanged(object sender, EventArgs e)
{
    RefreshWeekNumbers();
}
 
private void RefreshWeekNumbers()
{
    MultiMonthView view = this.radCalendar1.CalendarElement.View as MultiMonthView;
 
    MultiMonthViewElement viewElement = this.radCalendar1.CalendarElement.CalendarVisualElement as MultiMonthViewElement;
    foreach (MonthViewElement mView in viewElement.Children[0].Children[1].Children)
    {
        foreach (CalendarCellElement cellElement in mView.TableElement.Children)
        {
            if (cellElement.Date.Day == 1 && cellElement.Date.Month == 1 && cellElement.Text != "1" &&
                (cellElement.Text == "52" || cellElement.Text == "53" || cellElement.Text == "54")
            )
            {
                cellElement.Text = "1";
                cellElement.ToolTipText = "1";
            }
        }
    }
}

Please do not hesitate to contact us if you have any additional questions.

Regards,
Desislava
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
A. Drost
Top achievements
Rank 1
answered on 28 Mar 2014, 07:06 AM
Thank you very much!
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
A. Drost
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
A. Drost
Top achievements
Rank 1
Share this question
or