Button to add Appointment with Custom AppointmentEditForm - Event

2 posts, 1 answers
  1. Yanick
    Yanick avatar
    3 posts
    Member since:
    Dec 2018

    Posted 03 Mar Link to this post

    Hi,

    I have created a custom appointment edit form. In my main form I added a button to add new appointment to the scheduler.

    private void btnAddMessage_Click(object sender, EventArgs e)
           {
     
               if (radScheduler.SelectionBehavior.HasCellsSelected)
               {
                   radScheduler.Appointments.Add(new AppointmentATC(radScheduler.SelectionBehavior.GetSelectedInterval().Start, radScheduler.SelectionBehavior.GetSelectedInterval().Duration));
                   radScheduler.ShowAppointmentEditDialog(radScheduler.Appointments[radScheduler.Appointments.Count - 1], false);
               }
               else
               {
                   radScheduler.Appointments.Add(new AppointmentATC(DateTime.Now, TimeSpan.FromHours(0.5)));
                   radScheduler.ShowAppointmentEditDialog(radScheduler.Appointments[radScheduler.Appointments.Count - 1], false);
               }
           }

     

    When I click the button everything work fine.

     

    The problem is :

    When I click OK button the event AppointmentAdded was not trigger. But when I double click cell in scheduler or when I use the context menu to add appointment with my custom form when I click the OK the event AppointmentAdded is Triggered.

    How can I add a button to add an appointment and when I click OK button on the EditAppointment form the event AppointmentAdded is triggered.

     

    Thank you!

     

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3216 posts

    Posted 04 Mar Link to this post

    Hello, Yanick,         

    When you call the ShowAppointmentEditDialog method, it requires passing an IEvent instance and a boolean value indicating whether it is a recurring appointment or not. If you pass an existing appointment, it is normal that the AppointmentAdded event won't be fired because you actually don't create a new appointment, but edit an existing one. 

    However, the proper API for creating a new appointment via showing the edit dialog is to use the RadScheduler.AddNewAppointmentWithDialog:
    private void radButton1_Click(object sender, EventArgs e)
    {
        if (radScheduler1.SelectionBehavior.HasCellsSelected)
        {
            this.radScheduler1.AddNewAppointmentWithDialog(radScheduler1.SelectionBehavior.GetSelectedInterval(), false, this.radScheduler1.Resources);
        }
        else
        {
            radScheduler1.Appointments.Add(new Appointment(DateTime.Now, TimeSpan.FromHours(0.5)));
            radScheduler1.ShowAppointmentEditDialog(radScheduler1.Appointments[radScheduler1.Appointments.Count - 1], false);
        }
    }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top