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

Setting Start & End display dates in code

3 Answers 60 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Froggy
Top achievements
Rank 2
Froggy asked on 14 May 2012, 03:46 PM
Hi,

I want to control the calendar display month, not by user swipe but by "previous" & "next" buttons.  So I made a page with a calendar & 2 butons.

To do this, I use the following method:

            // Set for the start of this month.. 
            DateTime calendarDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);

.....

private void displayCalendar() {
     
radCalendar.DisplayDateStart = calendarDate;
       // Calculate the end month
              DateTime endDate = calendarDate;
              endDate = endDate.AddMonths(1);
              //endDate = endDate.AddDays(-1); // This is the end of the month
              radCalendar.DisplayDateEnd = endDate;
}

The first time I use this code I get the month of "May" displayed.  No problem.  It works.  But.....

Then I have this event:

        private void buttonCalendarPrevious_Click(object sender, RoutedEventArgs e)
        {
            calendarDate = calendarDate.AddMonths(-1);
            displayCalendar();
        }

But this is not working.  I get the error ArgumentOutOfRange {"Invalid DisplayDateEnd value.\r\nParameter name: sender"}

I checked the dates, and checked them again.  They are correct, Start is 01/04/2012.  End is 01/05/2012.

Maybe I do something wrong here.  But it seems I cannot set the range again after initializing the calendar.

How can I manage the display of the calendar and flip months using code ?

Thanks,
Steven

3 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 14 May 2012, 05:04 PM
Hi Steven,

Thank you for your interest in RadCalendar.

When you are changing the display dates, RadCalendar is checking if they are valid and you can't set the DisplayDateEnd to a date that is before DisplayDate or the DisplayDateStart to a date that is after DisplayDate.
What you need in order to change the month that is currently displayed is just to change the DisplayDate:
private void buttonCalendarPrevious_Click(object sender, RoutedEventArgs e)
{
       calendar.DisplayDate = calendar.DisplayDate.AddMonths(-1);
}
 
private void buttonCalendarNext_Click(object sender, RoutedEventArgs e)
{
       calendar.DisplayDate = calendar.DisplayDate.AddMonths(1);
}
And if you want not to allow the user to change the month with the DatePicker that is used for the name of the month, you can make it ReadOnly by adding the following style to the resources of your page:
<UserControl.Resources>
    <Style TargetType="telerikInput:RadDatePicker">
        <Setter Property="IsReadOnly" Value="True"/>
    </Style>
</UserControl.Resources>
I hope this information helps. Have a nice day!

Regards,
Todor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Froggy
Top achievements
Rank 2
answered on 15 May 2012, 09:36 AM
Hi,

I was able to get the display month working with the buttons, thanks for that.

However, I cannot disable the swipe action on the calendar.  That is when the user swipes over the calendar the month is changing.  I want to disable this option.  How can I do that??

thanks!
S-.
0
Froggy
Top achievements
Rank 2
answered on 15 May 2012, 09:44 AM
found it!

IsHitTestVisible="False"

Tags
Calendar
Asked by
Froggy
Top achievements
Rank 2
Answers by
Todor
Telerik team
Froggy
Top achievements
Rank 2
Share this question
or