Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Scheduler and Reminder > Drag Appointment to another hour - Validation

Not answered Drag Appointment to another hour - Validation

Feed from this thread
  • Frederico Fernandes avatar

    Posted on Nov 29, 2011 (permalink)

    Hi,

    When user drag an appointment to another hour, i want to do a validation to verify if that hour is prior than current date. The only event i see i can do that is in AppointmentFormatting, beacuase in CollectionChanged there is no changes in this case. However, it isn't possible to show a messagebox in AppointmentFormatting (gives an exception "Target invocation ...").

    So my question is: how can i validate when user drag an appointment to another hour an show a messagebox to warn about this validation.

    Thanks.

    Reply

  • Ivan Todorov Ivan Todorov admin's avatar

    Posted on Dec 2, 2011 (permalink)

    Hello Frederico,

    Thank you for contacting us.

    The most appropriate event for this case is the AppointmentDropping event. It occurs when the user drops an appointment with the mouse. Using the event arguments, you can get the date at which the appointment is being dropped and you can cancel the drop operation if the appointment does not pass the validation.

    Here is a sample implementation:
    void radScheduler1_AppointmentDropping(object sender, Telerik.WinControls.UI.AppointmentMovingEventArgs e)
    {
     
        if (e.NewDate < DateTime.Now)
        {
            e.Cancel = true;
            RadMessageBox.Show("Cannot move appointment!");
        }
    }

    I hope you find this useful. Let me know if you have any further questions.

    Greetings,
    Ivan Todorov
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

    Reply

  • Frederico Fernandes avatar

    Posted on Dec 5, 2011 (permalink)

    Hello Ivan,

    Thanks for your post, but that event for radscheduler "AppointmentDropping" exists in Telerik 2011 Q1?

    Reply

  • Ivan Todorov Ivan Todorov admin's avatar

    Posted on Dec 6, 2011 (permalink)

    Hi Frederico Fernandes,

    Indeed, the AppointmentDropping event was introduced in Q2 2011 SP1. In your version, you can use the AppointmentDropping event of the DragDropBehavior of RadScheduler. However, there is a tricky moment that the instance of this behavior is changed after some operations (for example a changed view). The following code snippet demonstrates how you can subscribe and handle this event and also check if the instance of the DragDropBehavior has changed:
    public partial class Form1 : Form
    {
        AppointmentDraggingBehavior oldBehavior;
     
        public Form1()
        {
            InitializeComponent();
     
            this.oldBehavior = this.radScheduler1.SchedulerElement.DragDropBehavior;
            this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentDropping += DragDropBehavior_AppointmentDropping;
            this.radScheduler1.MouseDown += new MouseEventHandler(radScheduler1_MouseDown);
        }
     
        void radScheduler1_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.radScheduler1.SchedulerElement.DragDropBehavior != oldBehavior)
            {
                oldBehavior = this.radScheduler1.SchedulerElement.DragDropBehavior;
                this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentDropping += DragDropBehavior_AppointmentDropping;
            }
        }
     
        void DragDropBehavior_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
        {
            if (e.NewDate < DateTime.Now)
            {
                RadMessageBox.Show("Invalid Date!");
                e.Cancel = true;
            }
        }
    }

    I hope this will help you. Should you have any further questions, do not hesitate to ask.

    Regards,
    Ivan Todorov
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > Scheduler and Reminder > Drag Appointment to another hour - Validation
Related resources for "Drag Appointment to another hour - Validation"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]