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

Catching Appointments Deletion

3 Answers 110 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Christophe Grasso
Top achievements
Rank 1
Christophe Grasso asked on 15 Feb 2011, 11:39 AM
I guys,

I need to react to Appointment changes in the scheduler. In order to do so, I subscribed to the CollectionChanged event declared by the Appointments collection in the scheduler :

radScheduler1.Appointments.CollectionChanged += new NotifyCollectionChangedEventHandler(Appointments_CollectionChanged);

I have no problem on Add and ItemChanged actions, but I can't find the Appointment object in the e.OldItems collection on Remove action. I just keep on getting a null reference exception :

public event ControlAddInEventHandler OnAppointmentsCollectionChanged;
void Appointments_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            try
            {
                if (OnAppointmentsCollectionChanged != null) {
                    switch (e.Action) {
                        case NotifyCollectionChangedAction.Add:
                            foreach (Appointment ap in e.NewItems)
                            {
                                OnAppointmentsCollectionChanged(1, ap.Subject);
                            }                   
                        break;
                        case NotifyCollectionChangedAction.ItemChanged:
                        case NotifyCollectionChangedAction.Remove:
                            foreach (Appointment ap in e.OldItems)
                            {
                                OnAppointmentsCollectionChanged(2, ap.Subject);
                            }
                        break;
                        default: break;
                    }
                }
            }
            catch (Exception ex)
            {
                OnAppointmentsCollectionChanged(3, ex.Message);
            }            
        }

Thank you for your help :)

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 15 Feb 2011, 12:02 PM
Hello,

You can catch the appointment that is being removed in the following way:

void Appointments_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Remove)
    {
        Appointment app = (Appointment)e.NewItems[0];
        MessageBox.Show(app.Subject);
    }
}

E.g. Create some appointments, then highlight one and press delete. The messagebox will show thesubject of the appointment that is being deleted.
Hope that helps
Richard
0
Christophe Grasso
Top achievements
Rank 1
answered on 15 Feb 2011, 12:28 PM
Thank you for the quick answer Richard ! Everything works fine now !

According to http://msdn.microsoft.com/en-us/library/system.collections.specialized.notifycollectionchangedeventargs.olditems(v=vs.90).aspx
, the deleted appointment should be found in e.OldItems... that's odd but as long as I can find it in e.NewItems, I don't really care.
0
Richard Slade
Top achievements
Rank 2
answered on 15 Feb 2011, 12:30 PM
Glad I could be of help.
All the best
Richard
Tags
Scheduler and Reminder
Asked by
Christophe Grasso
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Christophe Grasso
Top achievements
Rank 1
Share this question
or