Back to Devexpress

SchedulerDataStorage.AppointmentChanging Event

windowsforms-devexpress-dot-xtrascheduler-dot-schedulerdatastorage-de0ee21c.md

latest7.1 KB
Original Source

SchedulerDataStorage.AppointmentChanging Event

Fires when an appointment is about to change.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event PersistentObjectCancelEventHandler AppointmentChanging
vb
Public Event AppointmentChanging As PersistentObjectCancelEventHandler

Event Data

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

PropertyDescription
CancelGets or sets whether to cancel the operation.
ObjectGets the persistent object (appointment, resource or appointment dependency) for which the event occurs. Inherited from PersistentObjectEventArgs.

Remarks

The AppointmentChanging event is raised when changing an appointment’s property. The appointment whose property is changed is identified by the event parameter’s PersistentObjectEventArgs.Object property. Set the PersistentObjectCancelEventArgs.Cancel to true to roll back changes and cancel the operation.

If you cancel a change and this causes a conflict between Appointment start and end dates, the Scheduler Control discards the cancel operation and allows the change that triggered this event.

Important

Do not modify the appointment’s data source or data binding within this event handler. It results in the current appointment being disposed of, and consequently, an unhandled exception occurs.

Advanced Appointment Data

Cast PersistentObjectCancelEventArgs objects to the AdvPersistentObjectCancelEventArgs type to access additional information about the appointment being modified.

  • PropertyName - returns the name of the modified appointment property.
  • OldValue - the previous value of the modified appointment property.
  • NewValue - the new value of the modified appointment property.

Example 1

This event handler restricts the end-user from modifying appointments with busy status.

View Example

csharp
private void SchedulerStorage1_AppointmentChanging(object sender, PersistentObjectCancelEventArgs e) {
    if (((DevExpress.XtraScheduler.AdvPersistentObjectCancelEventArgs)e).PropertyName == "StatusKey") {
        return;
    }
    object busyKey = schedulerDataStorage1.Appointments.Statuses.GetByType(AppointmentStatusType.Busy).Id;
    if (((Appointment)e.Object).StatusKey.Equals(busyKey)) e.Cancel = true;
}
vb
Private Sub SchedulerStorage1_AppointmentChanging(ByVal sender As Object, ByVal e As PersistentObjectCancelEventArgs)
    If CType(e, DevExpress.XtraScheduler.AdvPersistentObjectCancelEventArgs).PropertyName = "StatusKey" Then
        Return
    End If
    Dim busyKey As Object = schedulerDataStorage1.Appointments.Statuses.GetByType(AppointmentStatusType.Busy).Id
    If CType(e.Object, Appointment).StatusKey.Equals(busyKey) Then
        e.Cancel = True
    End If
End Sub

Example 2

The code sample below prevents end-users from assigning empty string values to the appointment Appointment.Location property.

csharp
private void DataStorage_AppointmentChanging(object sender, PersistentObjectCancelEventArgs e) {
    AdvPersistentObjectCancelEventArgs advArgs = (AdvPersistentObjectCancelEventArgs)e;
    if (advArgs.PropertyName == "Location" && advArgs.NewValue == "") e.Cancel = true;
}
vb
Private Sub DataStorage_AppointmentChanging(ByVal sender As Object, ByVal e As PersistentObjectCancelEventArgs)
    Dim advArgs As AdvPersistentObjectCancelEventArgs = CType(e, AdvPersistentObjectCancelEventArgs)
    If advArgs.PropertyName = "Location" AndAlso advArgs.NewValue = "" Then
        e.Cancel = True
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AppointmentChanging event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-scheduler-create-appointment-edit-form-with-custom-fields/CS/SimpleCustomFields/Form1.cs#L20

csharp
schedulerDataStorage1.AppointmentsInserted += new PersistentObjectsEventHandler(this.OnApptChangedInsertedDeleted);
schedulerDataStorage1.AppointmentChanging += SchedulerStorage1_AppointmentChanging;
schedulerDataStorage1.AppointmentsChanged += new PersistentObjectsEventHandler(this.OnApptChangedInsertedDeleted);

winforms-scheduler-create-appointment-edit-form-with-custom-fields/VB/SimpleCustomFields/Form1.vb#L22

vb
AddHandler schedulerDataStorage1.AppointmentsInserted, AddressOf OnApptChangedInsertedDeleted
AddHandler schedulerDataStorage1.AppointmentChanging, AddressOf SchedulerStorage1_AppointmentChanging
AddHandler schedulerDataStorage1.AppointmentsChanged, AddressOf OnApptChangedInsertedDeleted

See Also

AppointmentsChanged

SchedulerDataStorage Class

SchedulerDataStorage Members

DevExpress.XtraScheduler Namespace