Back to Devexpress

SchedulerDataStorage.AppointmentInserting Event

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

latest5.8 KB
Original Source

SchedulerDataStorage.AppointmentInserting Event

Allows you to cancel the insertion of an appointment.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event PersistentObjectCancelEventHandler AppointmentInserting
vb
Public Event AppointmentInserting As PersistentObjectCancelEventHandler

Event Data

The AppointmentInserting 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 AppointmentInserting event is raised before an appointment is added to the AppointmentBaseCollection collection and allows you to cancel the operation. The event parameter’s PersistentObjectEventArgs.Object property allows the processed appointment to be identified. To prevent it from being added, set the PersistentObjectCancelEventArgs.Cancel property to true.

Note

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.

Tip

The SchedulerDataStorage.AppointmentsInserted event is raised after the SchedulerDataStorage.AppointmentInserting event, when appointments are already in the storage and are saved to the external data source (if any). At the moment, you cannot prevent them from being saved.

To validate appointment insertion, you can get properties of the appointment being inserted by casting the e.Object parameter to the Appointment type. The following example adds a timestamp to the created appointment:

View Example

csharp
private void SchedulerStorage1_AppointmentInserting(object sender, PersistentObjectCancelEventArgs e) {
    if (((Appointment)e.Object).Start < DateTime.Now) e.Cancel = true;
}
vb
Private Sub SchedulerStorage1_AppointmentInserting(ByVal sender As Object, ByVal e As PersistentObjectCancelEventArgs)
    If CType(e.Object, Appointment).Start < Date.Now Then
        e.Cancel = True
    End If
End Sub

Tip

You can use the SchedulerControl.InitNewAppointment event for appointment initialization.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AppointmentInserting 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#L18

csharp
schedulerDataStorage1.AppointmentInserting += SchedulerStorage1_AppointmentInserting;
schedulerDataStorage1.AppointmentsInserted += new PersistentObjectsEventHandler(this.OnApptChangedInsertedDeleted);

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

vb
AddHandler schedulerDataStorage1.AppointmentInserting, AddressOf SchedulerStorage1_AppointmentInserting
AddHandler schedulerDataStorage1.AppointmentsInserted, AddressOf OnApptChangedInsertedDeleted

See Also

AllowAppointmentCreate

InitNewAppointment

AppointmentsInserted

SchedulerDataStorage Class

SchedulerDataStorage Members

DevExpress.XtraScheduler Namespace