How can I setup the Calendar.DateTimeFormat.CalendarWeekRule property from a TreeListDateTimeColumnEditor

4 posts, 0 answers
  1. Ivan
    Ivan avatar
    2 posts
    Member since:
    Jun 2011

    Posted 18 Aug 2011 Link to this post

    I want to setup  the Calendar.DateTimeFormat.CalendarWeekRule property in the Edit Format for my Tree List control
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 23 Aug 2011 Link to this post

    Hi Ivan,

    You could hook up the ItemDataBound event and in it you should check whether the item is TreeListEditFormItem. After that cast the e.Item as TreeListEditFormItem. Next use the FindControl method to find the desired control. After that you receive all the functionality of the Calendar.

    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
                {          
                    if (e.Item is TreeListEditFormItem)
                    {
                        TreeListEditFormItem editedItem = e.Item as TreeListEditFormItem;
                        RadCalendar rCalendar = (RadCalendar)editedItem.FindControl("RadCalendar1");
                        rCalendar.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFourDayWeek;
                    }
                }

    The illustrated approach, could be used to find any controls within TreeListEditFormItem.

    Regards,
    Andrey
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ivan
    Ivan avatar
    2 posts
    Member since:
    Jun 2011

    Posted 08 Sep 2011 Link to this post

    I found this way but I have a read only exception please can you help me

    if (e.Column.DataField == "StartDate")
    {
        e.CustomEditorInitializer = new TreeListCreateCustomEditorDelegate(delegate
        {
            TreeListDateTimeColumnEditor stDate = new TreeListDateTimeColumnEditor(e.Column);
            stDate.DatePickerControl.Culture.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFourDayWeek;
     
            return stDate;
        });
    }
  5. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 12 Sep 2011 Link to this post

    Hello Ivan,

    Thank you for getting back to us.

    Please check the following code and see whether it is suitable for your scenario.
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
            {
                if (e.Item is TreeListEditFormItem)
                {               
                    TreeListEditFormItem editedItem = e.Item as TreeListEditFormItem;
                    RadDatePicker radDatePicker = (RadDatePicker)editedItem.FindControl("RadDatePicker1");
                    var calendar = radDatePicker.Calendar;               
                    System.Globalization.CultureInfo c = new System.Globalization.CultureInfo(calendar.CultureInfo.ToString());
                    c.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFullWeek;
                    calendar.CultureInfo = c;                              
                }
            }


    Although if you prefer the other approach, then you could use the following code:
    if (e.Column.DataField == "StartDate")
                {
                    e.CustomEditorInitializer = new TreeListCreateCustomEditorDelegate(delegate
                    {
                        TreeListDateTimeColumnEditor stDate = new TreeListDateTimeColumnEditor(e.Column);
                        var calendar = stDate.DatePickerControl.Calendar;
                        System.Globalization.CultureInfo c = new System.Globalization.CultureInfo(calendar.CultureInfo.ToString());
                        c.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFullWeek;
                        calendar.CultureInfo = c;
                        return stDate;
                    });
                }

    Do not hesitate to contact us again, if you have more questions.

    Greetings,
    Andrey
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top