Back to Devexpress

SchedulerControl.CustomAppointmentSort Event

windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-47b9f070.md

latest4.5 KB
Original Source

SchedulerControl.CustomAppointmentSort Event

Allows you to sort appointments in any custom order.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event CustomAppointmentSortEventHandler CustomAppointmentSort
vb
Public Event CustomAppointmentSort As CustomAppointmentSortEventHandler

Event Data

The CustomAppointmentSort event's data class is DevExpress.XtraScheduler.CustomAppointmentSortEventArgs.

Remarks

The CustomAppointmentSort event raises for each encountered appointment, and compares it with an appointment that will be placed after the currently processed appointment if you do not implement a custom sort algorithm.

  • e.AppointmentLayoutInfo1 parameter - stores information about the appointment that will go first should you leave the default sort order. The returned IAppointmentLayoutInfo object allows you to obtain the appointment itself, its related resource, and start/end dates.
  • e.AppointmentLayoutInfo2 parameter - stores information about the appointment that will go after the first appointment if you leave the default sort order.

Read these parameters to compare the appointments, and specify the integer e.Result property depending on which of the two appointments should go first.

  • Set the e.Result to any negative value if the appointment related to the e.AppointmentLayoutInfo1 parameter should go first.
  • Set the e.Result to any positive value if the appointment related to the e.AppointmentLayoutInfo2 parameter should go first.
  • Set the e.Result to 0 if both appoitnments are equal and the Scheduler should utilize default sort mechanism to arrange them.

The Timeline View demo module illustrates how to sort appointments by their Statuses: appointments with the “Out of Office” status are placed after appointments with no statuses. Note that you can sort appointments regardless of whether they have been grouped (see SchedulerControl.CustomAppointmentGroup) or not.

csharp
void SchedulerControl1_CustomAppointmentSort(object sender, CustomAppointmentSortEventArgs e) {
    Appointment apt1 = e.AppointmentLayoutInfo1.Appointment;
    Appointment apt2 = e.AppointmentLayoutInfo2.Appointment;
    //compare by statuses
    e.Result = ((int)apt1.StatusKey).CompareTo((int)apt2.StatusKey);
    if (e.Result != 0)
        return;
    //if statuses are the same, compare by dates
    e.Result = apt1.Start.CompareTo(apt2.Start);
    if (e.Result != 0)
        return;
    e.Result = -apt1.End.CompareTo(apt2.End);
}
vb
Private Sub SchedulerControl1_CustomAppointmentSort(ByVal sender As Object, ByVal e As CustomAppointmentSortEventArgs)
    Dim apt1 As Appointment = e.AppointmentLayoutInfo1.Appointment
    Dim apt2 As Appointment = e.AppointmentLayoutInfo2.Appointment
    'compare by statuses
    e.Result = CInt(Math.Truncate(apt1.StatusKey)).CompareTo(CInt(Math.Truncate(apt2.StatusKey)))
    If e.Result <> 0 Then
        Return
    End If
    'if statuses are the same, compare by dates
    e.Result = apt1.Start.CompareTo(apt2.Start)
    If e.Result <> 0 Then
        Return
    End If
    e.Result = -apt1.End.CompareTo(apt2.End)
End Sub

See Also

SchedulerControl.CustomAppointmentGroup

Appointments

SchedulerControl Class

SchedulerControl Members

DevExpress.XtraScheduler Namespace