Issue Deleting Appointments Programmatically

7 posts, 0 answers
  1. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 26 Feb 2013 Link to this post

    Hi

    I'm having an issue trying to delete appointments programmatically. What I'm doing is handling the AppointmentAdded Event and contrasting the appointment subject (which will contain someones name) against a DB. If the appointment subject (Name) does not appear in the aforementioned DB, then the appointment must be deleted. The problem is that the appointment refuses to be deleted.

    Here's the code that I'm using:
    Private Sub RadScheduler1_AppointmentAdded(sender As Object, e As Telerik.WinControls.UI.AppointmentAddedEventArgs) Handles RadScheduler1.AppointmentAdded
          Dim app As AppointmentWithPhone = TryCast(e.Appointment, AppointmentWithPhone)
     
          If NameExistsInDB(app.Subject) = False Then
              Debug.WriteLine("Before: " & RadScheduler1.Appointments.Count)
     
              Me.RadScheduler1.Appointments.Remove(app)
     
              Debug.WriteLine("After: " & RadScheduler1.Appointments.Count)
          End If
      End Sub

    The output in both debug cases is the same. If I have two appointments and add a third with a name that does not exist in the DB (thus forcing my application to enter inside the "IF") I get this:

    Debug output:
    Before: 3
    After: 3


    Can you help me out? Am I doing it the right way or is there some other way to delete an appointment?
    Thanks!
  2. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 26 Feb 2013 Link to this post

    Well, I managed to solve the issue, but I think the solution works only for my scenario or a similar one.

    Here's what I did:
    I handled the CollectionChanging event, and filtered the newly added appointment using the NotifyCollectionChangedAction.Add property.

    So, the whole code ended up like this:
    Private Sub Appointments_CollectionChanging(sender As Object, e As NotifyCollectionChangingEventArgs)
        If e.Action = NotifyCollectionChangedAction.Add Then
            For Each app As AppointmentWithPhone In e.NewItems
                If NameExistsInDB(app.Subject) = False Then
                    e.Cancel = True
                End If
            Next
        End If
    End Sub

    I'm OK with this, however, my question persists. Why is that my other method didn't work?
    Thanks again!
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 01 Mar 2013 Link to this post

    Hello Matias,

    Thank you for writing.

    I tried to reproduce the issue you are experiencing with the first method but I was unable to do so. On my machine the appointment was removed every time. I noticed you are using a custom appointment, if you can provide more information on what appointments objects you are using I will be able to investigate the case further.

    Nevertheless, your second approach is the better solution in this case. It is better to do not add the appointment in the collection at all, than to add it an remove it.

    I hope this helps. Do not hesitate to write back with any further questions.

    All the best,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
  5. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 01 Mar 2013 Link to this post

    Hi Ivan,

    I'm not getting it, what do you mean by "appointment objects"? Can you please be more specific?
    I'm using a custom appointment, but it looks exactly like the one you provide in the tutorial, AppointmentWithPhone (Just a phone field).

    The appointment is created by Drag&Drop from a GridView using the code provided in the Drag&Drop example. Also, I give some format to the appointment (Background color, Shape, and so), and to persist it into my DB I handle the CollectionChanged event.

    I will be happy to provide more details, just not getting what you mean by "appointment objects".

    I look forward to your answer!
    Thanks again!

     - Matias
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 06 Mar 2013 Link to this post

    Hello Matias,

    Thank you for writing back.

    I was referring to the AppointmentWithPhone when I wrote "appointment object". This was the only thing I did not use in my test. Nevertheless, I tested the case again using the AppoinemtnWithEmail from our online help but still the result was the same. The remove worked as expected. I would kindly ask you to send me your project so I can investigate this further.

    Looking forward to your reply.

    Regards,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  7. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 06 Mar 2013 Link to this post

    Hi Ivan,

    Thanks for answering. I'm glad to tell you that I managed to solve the issue. It seems it was related to an error introduced by myself in the code for automatically saving the collection once modified.

    Thank you very much for your help on this, keep up the great work you guys are doing!
     - Matias
  8. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 07 Mar 2013 Link to this post

    Hi Matias,

    I am happy to hear that this issue is sorted out. Should you have any other questions, feel free to contact us.

    Kind regards,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top
UI for WinForms is Visual Studio 2017 Ready