Setting Start & End display dates in code

4 posts, 1 answers
  1. Froggy
    Froggy avatar
    16 posts
    Member since:
    Apr 2012

    Posted 14 May 2012 Link to this post

    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
  2. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 14 May 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. Froggy
    Froggy avatar
    16 posts
    Member since:
    Apr 2012

    Posted 15 May 2012 Link to this post

    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-.
  5. Froggy
    Froggy avatar
    16 posts
    Member since:
    Apr 2012

    Posted 15 May 2012 Link to this post

    found it!

    IsHitTestVisible="False"

Back to Top