Drag Appointment to another hour - Validation

4 posts, 0 answers
  1. Frederico Fernandes
    Frederico Fernandes avatar
    20 posts
    Member since:
    Oct 2009

    Posted 29 Nov 2011 Link to this post

    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.
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 02 Dec 2011 Link to this post

    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.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Frederico Fernandes
    Frederico Fernandes avatar
    20 posts
    Member since:
    Oct 2009

    Posted 05 Dec 2011 Link to this post

    Hello Ivan,

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

  5. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 06 Dec 2011 Link to this post

    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.

Back to Top