C1Calendar - Firing event if navigation button is been clicked

Posted by: grapecity on 18 September 2018, 1:46 am EST

    • Post Options:
    • Link

    Posted 18 September 2018, 1:46 am EST

    Hi,

    How I can determine whether a user has clicked on C1Calendar’s navigation buttons and further more, if - by clicking on that navigation button - either first date or last date are reached ?

    Thanks, Stephan

  • Posted 18 September 2018, 9:25 pm EST

    Hello,

    It seems like you are talking about the C1CalendarView control. Please note that it has no event related to the navigation buttons. Apologies for the inconvenience.

    Further, the C1DateEdit control of C1.Win.Calendar.4 has an UpDownButtonClick event where Delta property of event argument can be used to check if up or down button is pressed, as follows:

    private void c1DateEdit2_UpDownButtonClick(object sender, C1.Win.C1Input.UpDownButtonClickEventArgs e)
            {
                
                if (e.Delta==1)
                {
                    Console.WriteLine("Up Button Pressed");
                    
                }
                else if(e.Delta ==-1)
                    {
                    Console.WriteLine("Down Button Pressed");
                }
            }
    

    either first date or last date are reached ?

    Do you wish to check this with respect to a particular month? If yes, it can be done within the ValueChanged event of C1DateEdit, such that the Calendar.SelectedDate value is compared to the desired value. Say, for September:

     private void c1DateEdit2_ValueChanged(object sender, EventArgs e)
            {
                if (c1DateEdit2.Calendar.SelectedDate.Month == 09)
                {
                    if (c1DateEdit2.Calendar.SelectedDate.Day == 1)
                        Console.WriteLine("Start of the month!");
                    else if (c1DateEdit2.Calendar.SelectedDate.Day == 30)
                        Console.WriteLine("End of the month!");
                }
            }
    

    Best Regards,

    Esha

  • Posted 18 September 2018, 11:16 pm EST

    Hello Esha,

    Thanks for the fast reply.

    I’m currently developing an appointment schedule. I’m using C1.Win.C1Schedule.C1Calendar and C1.Win.C1Schedule.C1Schedule. My customer has a lot of appointments to manage. For this year and last year more than 40.000 combined.

    When I load the whole amount into C1Schedule at once it takes about 25 seconds until C1Schedule can be used again which is quite unexeptable for my customer. So what I’m trying to achieve is to load originally just a part of appointments and the others only if needed. To determine that, I thought I could use the navigation buttons of C1Calendar to have them firing an event if the user is trying to scroll past its FirstDate or LastDate property. Obviously I can’t. Is there another event around which I could use instead ?

    And what’s the best practise to add a bulk of appointments to C1Schedule without clearing the appointment storage and re-loading all the previous appointments again ?

    Thanks again,

    Stephan

  • Posted 19 September 2018, 8:09 pm EST

    Hi Stephan!

    Below are some points that you can take care of, in your project, to improve performance:

    1. Use BeginUpdate/EndUpdate methods of C1Shedule control. See here:

    http://help.grapecity.com/componentone/NetHelp/c1schedule/webframe.html#schedulerforwinforms2.html

    1. Set c1Schedule1.ShowReminderForm to false or don’t set reminders for appointments at all.

    2. Try to limit the number of appointments. If it is something that should repeat every day at same times, it must be much more easier and faster to create such appointments for single day or several days only. And for sure don’t create them for past times.

    3. Try to use simple not recurring appointments. Recurring appointments are more expensive from the performance point of view, as to create even single instance, control should count recurrence pattern. For simple appointments there are no additional expenses for this.

    If it still doesn’t help, then you can check if selected day(s) has changed using SelectionChanged event of C1Calendar:

    private void C1Calendar1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    //Your code here...
    }
    

    Hope it helps you.

    Best regards,

    Meenakshi

  • Posted 20 September 2018, 7:19 pm EST - Updated 3 October 2022, 3:58 pm EST

    Hi Meenakshi,

    Again, Thanks for your fast reply.

    I understand where you’re coming from and I really appreciated your advice.

    Therefore I’ve changed my approach and I’m gonna display only the current and the next 2 month of my customer’s appointments. Why 3 month ? Because he’s a general practitioner and he needs to have an overview of his oncoming appointsments. And since he’s a very popular doctor he’s got about 100 appointments per working day which makes up to 7.000 appointments per quarter to display. See C1Calendar1.jpg.

    I’m using C1Calendar to enable him to scroll to previous month or to those farther in the future. To do so I’d like him to use C1Calendar’s navigation buttons and its SelectedDatesChanged event. As long as I’m scrolling forward everything’s fine as the selected dates range changes automatically. See C1Calendar2.jpg.

    But scrolling backwards unfortunately doesn’t necessarily change the selected dates. See C1Calendar3.jpg.

    So as a workaround I would very much like a method in C1Calendar to determine which 3 month are currently displayed . But there’s none, right ? So could you please provide a alternative approach ?

    Thanks in advance,

    Stephan

  • Posted 20 September 2018, 7:23 pm EST

    Hi,

    I’ve noticed that those screenshots attached are sorted 2,1,3. Sorry for that.

    Stephan

  • Posted 23 September 2018, 8:21 pm EST

    Hi Stephan!

    Currently there is no such event to determine if visible months have been changed in C1Calendar control. Hence, I am forwarding this as enhancement request to the concerned team.

    And sorry, but there is no other appropriate workaround to achieve the requested behaviour.

    Best regards,

    Meenakshi

  • Posted 25 September 2018, 5:50 pm EST

    Hi

    Meanwhile, we could come up with the following workaround:

    1. Handle C1Calendar.Invalidated event to catch all situations when calendar rebuilds visible dates (not only button clicks, but also resizing and mouse wheel).

    2. In event handler for this event, compare previously saved display date range with the current one.

    3. If display date range has changed, perform required actions and save new display range for future reference.

    Note, application can use C1Calendar.GetDisplayRange method to get dates currently visible in UI. This method might cause exceptions if it is called during rebuilding UI, so it must be enclosed into try/catch. Here is a code snippet which should work:

    c1Calendar1.Invalidated += C1Calendar1_Invalidated;
    SelectionRange _lastRange;
    
    // save C1Calendar's display range
    private void C1Calendar1_Invalidated(object sender, InvalidateEventArgs e)
    {
           SelectionRange range = null;
           try
           {
                   range = c1Calendar1.GetDisplayRange(false);
           }
           catch
           {
                    // it is possible if call GetDisplayRange while calendar is rebuilding itself
                    return;
           }
    
           if (_lastRange == null || !range.Start.Equals(_lastRange.Start))
           // check whether display range changed
           {
                    // do needed actions here
                    // store new display range
                    _lastRange = range;
            }
    }
    

    Regards,

    Meenakshi

  • Posted 3 October 2018, 8:04 am EST

    Hi,

    I’ve tried out your work-around and I for now I can live with it, even though I’d really love to have an event firing whenever i use C1Calendar’s arrows.

    Thanks so far,

    Stephan

  • Posted 3 October 2018, 3:00 pm EST

    Hi Stephan!

    Yes, I understand your concern. I’ll update you once I have any information regarding the enhancement request of such event.

    Best regards,

    Meenakshi

  • Posted 31 July 2019, 12:34 am EST

    Hello,

    A new “DisplayRangeChanged” event is introduced in 2019V2 version which is fired when clicking on navigation buttons on C1Calendar. You can download the latest build from the following link:

    http://prerelease.componentone.com/dotnet40/c1winforms/2019-t2/C1WinForms-452_4.5.20192.375.zip

    Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels