Access context menu items New/Edit appointment

6 posts, 2 answers
  1. Smiljan
    Smiljan avatar
    8 posts
    Member since:
    Mar 2015

    Posted 20 Mar 2015 Link to this post

    Hi!

    I modified appointment edit/insert form with my own custom fields.

    Now I need to "tap into" New and Edit methods of the Context menu.

    I need to add some of my own code (code1) if New appointment is selected AND add my own code (code2) id Edit appointment is selected.
    How can I do this? Is there any possibility inside AppointmentEditForm class to differentiate if "New" or "Edit" was selected in context menu prior to openning AppointmentEditForm?

    Thank you for any kind of info.

    BR, Smiljan
  2. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 25 Mar 2015 Link to this post

    Hello Smiljan,

    Thank you for writing.

    By design, whether creating a new appointment or editing an existing one the same EditAppointmentDialog gets initialized.

    As it is explained in this article the right place to substitute the default EditAppointmentDialog is to handle the AppointmentEditDialogShowing event. Please note that in the handler you receive as an argument an appointment which may be an existing one or a new one. Checking if the appointment is part of the RadScheduler.Appointments collection will tell you if an appointment is about to be edited or created. Having this information you can plug your case specific code before instantiating the editor dialog. You can go even further and create different EditAppointmentDialog elements which may be used in different cases:
    private void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
    {
        if (this.radScheduler1.Appointments.Contains(e.Appointment))
        {
            //An appointment is about to be edited
        }
        else
        {
            //An appointment is about to be created
        }
    }

    Shortly, after a new EditAppointmentDialog is initialized, a call to the EditAppointment method is made. You could override it in your implementation of the dialog and follow a similar approach as shown above. Please see my code snippet below:
    public override bool EditAppointment(IEvent appointment, ISchedulerData schedulerData)
    {
        if ( ((RadScheduler)schedulerData).Appointments.Contains(appointment))
        {
            //An appointment is about to be edited
        }
        else
        {
            //An appointment is about to be created
        }
     
        return base.EditAppointment(appointment, schedulerData);
    }

    I hope this information helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Smiljan
    Smiljan avatar
    8 posts
    Member since:
    Mar 2015

    Posted 25 Mar 2015 in reply to Hristo Link to this post

    Great! THANK YOU for this helpful reply.
    One more question in this case - I want to transfer a value over to custom inherited class (some public variable definied in the custom inherited class - named "mode"). Now if I define it as "public int mode;" I'm not able to set it's value (access it) inside private void radScheduler1_AppointmentEditDialogShowing(object sender, Telerik.WinControls.UI.AppointmentEditDialogShowingEventArgs e) event.
    How can I transfere variable value over to the custom inherited EditForm class?

    For example I did change some of the code to accomodate this (please see if my solution is OK. But I think now on SaveChanges application takes about 5-10x more time to save into DB)

    // private IEditAppointmentDialog appointmentDialog = null; // original
    private AppointmentWithDataEditForm appointmentDialog = null; // my idea of solving this
    private void radScheduler1_AppointmentEditDialogShowing(object sender, Telerik.WinControls.UI.AppointmentEditDialogShowingEventArgs e)
    {
     if (appointmentDialog == null)
       appointmentDialog = new AppointmentWithDataEditForm(); this.appointmentDialog.mode = 0; // transfer value over to inherited custom EditForm
     e.AppointmentEditDialog = this.appointmentDialog;
    }
  5. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 30 Mar 2015 Link to this post

    Hi Smiljan,

    Thank you for writing.

    Changing the default EditAppointmentDialog should not affect the time for which an appointment is being saved in a database. If you are still experiencing any issue please try and isolate the problem in a separate project and upload it to some free cloud server, e.g. Dropbox. We will be happy to further investigate it.

    As to your question about passing data to the CustomAppointmentEditForm you could also achieve it by passing a parameter in the constructor. In this case the initialization of the edit form should look similar to this:
    public partial class CustomAppointmentEditForm : EditAppointmentDialog
    {
        private int mode;
     
        public CustomAppointmentEditForm()
        {
            InitializeComponent();
        }
     
        public CustomAppointmentEditForm(int mode)
            : this()
        {
            this.mode = mode;
        }
     
       //.............................................
    }

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  6. Smiljan
    Smiljan avatar
    8 posts
    Member since:
    Mar 2015

    Posted 30 Mar 2015 in reply to Hristo Link to this post

    Works like a charm! :)))
    Thank you!!!

    BR, Smiljan
  7. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 02 Apr 2015 Link to this post

    Hello,

    I am glad that the provided approach worked for your scenario.

    Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready