RadScheduler and CollectionChanged event with Start / End Dates

2 posts, 0 answers
  1. Chad
    Chad avatar
    11 posts
    Member since:
    Apr 2011

    Posted 25 Aug 2011 Link to this post

    Hello, thank you for looking at my question Telerik!

    I Have a calendar, that when someone moves an appointment via the edit dialog using the startDate and endDate dropdown, when they click OK it fires a collectionchanged event like it should, however i get that event fired 2 times, one for the Start Date (PropertyName = "StartDate" and once for EndDate (property name "EndDate") and of course any other data they might have changed ...

    My Question, how do i not get 2 events, how can i make it so when they change data ont he edit dialog and click OK i get ONE event, or somehow else know that a particular event was updated instead of getting field by field notification that tells me ok, this appointment was updated, then i can go and grab the properties of that Appointment object and save them to my datasource (Using WCF Web Services) with only 1 call,  the issue is i make 1 call to save the start date then right behind that i make a second call to save the end date and its messing things up !

    here is my collectionChanged event, thank you for the input !!

    void Appointments_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
            {
                if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged)
                {
                    if (e.NewItems.Count > 0 && e.OldItems.Count > 0)
                    {
                        DoctorAppointment newAppt = (DoctorAppointment) e.NewItems[0];
                        DoctorAppointment oldAppt = (DoctorAppointment) e.OldItems[0];
     
                        if ((e.PropertyName == "Start" || e.PropertyName == "End"))
                        {
                            sc.RescheduleAppointmentAsync(this.LoggedInUserID, newAppt.id, newAppt.Start, newAppt.End);
                        }
     
                        if (e.PropertyName == "status_id")
                        {
                            short followupid = newAppt.status_id.GetValueOrDefault(-1);
                            if (followupid > 0) {
                                sc.FollowupAppointmentAsync(this.LoggedInUserID, newAppt.id, followupid);
                            }
                        }
     
                        newAppt = null;
                        oldAppt = null;
                    }
                }
            }
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 29 Aug 2011 Link to this post

    Hi Chad,

    Thank you for contacting us.

    You can combine several update operations into one batch operation by using the BeginUpdate/EndUpdate methods of the Appointments collection, but in this case you will not be able to identify which appointment has been edited and you will need to send the whole collection to your service.

    A better approach is to update your records when the EditAppointmentDialog's ApplySettingsToEvent() method is called. This could be achieved by using a custom edit dialog as it is shown in the following code snippet:
    public class CustomEditAppointmentDialog : EditAppointmentDialog
    {
        protected override void ApplySettingsToEvent(IEvent targetEvent)
        {
            base.ApplySettingsToEvent(targetEvent);
     
           //use this.Appointment to get the settings
        }
     }

    To replace the default dialog with the custom one, subscribe to the AppointmentEditDialogShowing event of your scheduler:
    void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
    {
        e.AppointmentEditDialog = new CustomEditAppointmentDialog();
    }

    I hope you find this useful. Feel free to write back if you have any additional questions.

    All the best,
    Ivan Todorov
    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 WinForms is Visual Studio 2017 Ready
Back to Top