Back to Devexpress

SchedulerControl.AppointmentDrag Event

windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-ae1c7c1f.md

latest6.3 KB
Original Source

SchedulerControl.AppointmentDrag Event

Occurs when appointment is dragged in the Scheduler control.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event AppointmentDragEventHandler AppointmentDrag
vb
Public Event AppointmentDrag As AppointmentDragEventHandler

Event Data

The AppointmentDrag event's data class is AppointmentDragEventArgs. The following properties provide information specific to this event:

PropertyDescription
AdditionalAppointmentsProvides access to the collection of the additional dragged appointments.
AllowAllGets or sets whether the user can drag the appointment along time cells.
AllowThisAppointmentGets or sets whether the drag operation is allowed for a specific appointment when the user is dragging multiple appointments at the same time.
CopyEffectIndicates whether the drop effect in a drag-and-drop appointment operation is Copy.
EditedAppointmentGets the appointment being modified in the drag-and-drop event.
ForceUpdateFromStorageGets or sets whether the View is forced to query appointments from the storage.
HitIntervalGets the time interval represented by the time cell to which an appointment was dragged.
HitResourceGets the resource to which an appointment was dragged.
NewAppointmentResourceIdsGets or sets the IDs of resources for a new appointment.
SourceAppointmentGets the source appointment in the drag-and-drop event.

Remarks

If a user drags multiple appointments, this event fires for each of them.

The AdditionalAppointments property in event parameters allows you to re-arrange other appointments that were not dragged by a user. In the sample below, if a user is about to schedule the “Start” appointment so that it finishes later in time than the related “Finish” appointment starts, the latter appointment is added to the AdditionalAppointments collection.

csharp
void SchedulerControl1_AppointmentDrag(object sender, AppointmentDragEventArgs e) {
    if (e.SourceAppointment.Subject == "Start") {
        AppointmentBaseCollection visbileApts = schedulerControl1.ActiveView.GetAppointments();
        Appointment apt = visbileApts.Find(item => item.Subject == "Finish");
        if (apt == null)
            e.AdditionalAppointments.Clear();
        else {
            if (e.SourceAppointment != apt) {
                if (e.EditedAppointment.End > apt.Start)
                    e.AdditionalAppointments.Add(apt);
                else e.AdditionalAppointments.Clear(); 
            }
        }
    }
}
vb
Private Sub SchedulerControl1_AppointmentDrag(ByVal sender As Object, ByVal e As AppointmentDragEventArgs)
    If e.SourceAppointment.Subject = "Start" Then
        Dim visbileApts As AppointmentBaseCollection = schedulerControl1.ActiveView.GetAppointments()
        Dim apt As Appointment = visbileApts.Find(Function(item) item.Subject = "Finish")
        If apt Is Nothing Then
            e.AdditionalAppointments.Clear()
        Else
            If e.SourceAppointment IsNot apt Then
                If e.EditedAppointment.End > apt.Start Then
                    e.AdditionalAppointments.Add(apt)
                Else
                    e.AdditionalAppointments.Clear()
                End If
            End If
        End If
    End If
End Sub

To specify new positions for AdditionalAppointments, handle the SchedulerControl.AppointmentsDrag event.

csharp
private void SchedulerControl1_AppointmentsDrag(object sender, DevExpress.XtraScheduler.AppointmentsDragEventArgs e) {
    if (e.AdditionalAppointmentInfos.Count <= 0)
        return;
    AppointmentDragInfo aptInfo = e.AdditionalAppointmentInfos[0];
    if (e.PrimaryAppointmentInfos[0].EditedAppointment.End > aptInfo.SourceAppointment.Start)
        aptInfo.EditedAppointment.Start = e.PrimaryAppointmentInfos[0].EditedAppointment.End;
}
vb
Private Sub SchedulerControl1_AppointmentsDrag(ByVal sender As Object, ByVal e As DevExpress.XtraScheduler.AppointmentsDragEventArgs)
    If e.AdditionalAppointmentInfos.Count <= 0 Then
        Return
    End If
    Dim aptInfo As AppointmentDragInfo = e.AdditionalAppointmentInfos(0)
    If e.PrimaryAppointmentInfos(0).EditedAppointment.End > aptInfo.SourceAppointment.Start Then
        aptInfo.EditedAppointment.Start = e.PrimaryAppointmentInfos(0).EditedAppointment.End
    End If
End Sub

See Also

SchedulerControl Class

SchedulerControl Members

DevExpress.XtraScheduler Namespace