This is a migrated thread and some comments may be shown as answers.

Drag Appointment to another hour - Validation

3 Answers 64 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Frederico Fernandes
Top achievements
Rank 1
Frederico Fernandes asked on 29 Nov 2011, 10:30 AM
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.

3 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 02 Dec 2011, 09:32 AM
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.

0
Frederico Fernandes
Top achievements
Rank 1
answered on 05 Dec 2011, 03:58 PM
Hello Ivan,

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

0
Ivan Todorov
Telerik team
answered on 06 Dec 2011, 03:57 PM
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.

Tags
Scheduler and Reminder
Asked by
Frederico Fernandes
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Frederico Fernandes
Top achievements
Rank 1
Share this question
or