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

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

3 Answers 55 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 18 Aug 2011, 05:41 PM
I want to setup  the Calendar.DateTimeFormat.CalendarWeekRule property in the Edit Format for my Tree List control

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 24 Aug 2011, 04:55 AM
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 >>

0
Ivan
Top achievements
Rank 1
answered on 08 Sep 2011, 02:51 PM
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;
    });
}
0
Andrey
Telerik team
answered on 12 Sep 2011, 05:02 PM
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.
Tags
TreeList
Asked by
Ivan
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or