Calendar WeekNummering

5 posts, 0 answers
  1. A. Drost
    A. Drost avatar
    11 posts
    Member since:
    Jul 2009

    Posted 14 Mar 2014 Link to this post

    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
  2. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 19 Mar 2014 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. A. Drost
    A. Drost avatar
    11 posts
    Member since:
    Jul 2009

    Posted 21 Mar 2014 in reply to Dess Link to this post

    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
  5. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 26 Mar 2014 Link to this post

    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.

     
  6. A. Drost
    A. Drost avatar
    11 posts
    Member since:
    Jul 2009

    Posted 28 Mar 2014 Link to this post

    Thank you very much!
Back to Top
UI for WinForms is Visual Studio 2017 Ready