Back to Devexpress

SchedulerControl.AllowAppointmentDelete Event

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

latest7.1 KB
Original Source

SchedulerControl.AllowAppointmentDelete Event

Occurs when the SchedulerControl checks whether the appointment can be deleted. The event fires only if the SchedulerOptionsCustomization.AllowAppointmentDelete property is set to Custom.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event AppointmentOperationEventHandler AllowAppointmentDelete
vb
Public Event AllowAppointmentDelete As AppointmentOperationEventHandler

Event Data

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

PropertyDescription
AllowGets or sets a value indicating whether an end-user is allowed to perform a particular action.
AppointmentGets the appointment for which the event was raised. Inherited from AppointmentEventArgs.
RecurringGets or sets a value indicating if the appointment is recurring.

Remarks

The AllowAppointmentDelete event is fired when the SchedulerControl verifies the ability to remove an appointment. Such verification is required to update the command state (ICommandUIState) of the commands available for the end-user. Hence the AllowAppointmentDelete event for a particular appointment occurs not only once, but more often than expected.

Handle the AllowAppointmentDelete event to restrict end-users from deleting an appointment. The appointment to delete can be accessed via the AppointmentEventArgs.Appointment property. To deny end-users the ability to delete an appointment , set the AppointmentOperationEventArgs.Allow property to false.

We advise that you use only simple checks to determine whether an appointment can be deleted. Methods which require user response are not suitable when handling this event.

Note that the AllowAppointmentDelete event enables you to prevent an appointment from being deleted by end-user actions. To protect an appointment from deletion in all situations, handle the SchedulerStorageBase.AppointmentDeleting event.

Note

The AllowAppointmentDelete event is fired only if the SchedulerOptionsCustomization.AllowAppointmentDelete property is set to UsedAppointmentType.Custom.

Example

This example demonstrates how to implement custom rules for editing and deleting appointments. The code below allows an appointment to be edited only by its owner (the end-user who created it). To do this it’s necessary to set the SchedulerOptionsCustomization.AllowAppointmentEdit and SchedulerOptionsCustomization.AllowAppointmentDelete properties to UsedAppointmentType.Custom, and handle the SchedulerControl.AllowAppointmentEdit and SchedulerControl.AllowAppointmentDelete events to implement custom logic for editing appointments.

csharp
using DevExpress.XtraScheduler;
// ...

private void schedulerControl1_AllowAppointmentDelete(object sender, 
    AppointmentOperationEventArgs e) {
   // Allow only the user who created this appontment to delete it.
   e.Allow = CanUserModifyThisAppointment(e.Appointment);
}
private void schedulerControl1_AllowAppointmentEdit(object sender, 
    AppointmentOperationEventArgs e) {
   // Allow only the user who created this appontment to modify it.
   e.Allow = CanUserModifyThisAppointment(e.Appointment);
}
// Determine if the current user is the same 
// as the one who created the specified appointment 
bool CanUserModifyThisAppointment(Appointment apt) {
   object obj = apt.CustomFields["Owner"];
   if (obj == null)
      return true;
   string appointmentOwner = obj.ToString();
   if (appointmentOwner == String.Empty)
      return true;
   return (String.Compare(appointmentOwner, tbUserName.Text, true) == 0);
}
vb
Imports DevExpress.XtraScheduler
' ...

Private Sub schedulerControl1_AllowAppointmentDelete(ByVal sender As Object, _
ByVal e As AppointmentOperationEventArgs)
   ' Allow only the user who created this appontment to delete it.
   e.Allow = CanUserModifyThisAppointment(e.Appointment)
End Sub
Private Sub schedulerControl1_AllowAppointmentEdit(ByVal sender As Object, _
ByVal e As AppointmentOperationEventArgs)
   ' Allow only the user who created this appontment to modify it.
   e.Allow = CanUserModifyThisAppointment(e.Appointment)
End Sub
' Determine if the current user is the same 
' as the one who created the specified appointment 
Private Function CanUserModifyThisAppointment(ByVal apt As Appointment) As Boolean
   Dim obj As Object = apt.CustomFields("Owner")
   If obj Is Nothing Then
      Return True
   End If
   Dim appointmentOwner As String = obj.ToString()
   If appointmentOwner = String.Empty Then
      Return True
   End If
   Return (String.Compare(appointmentOwner, tbUserName.Text, True) = 0)
End Function

See Also

How to: Prevent End-Users from Editing Appointments

AllowAppointmentDelete

AppointmentDeleting

SchedulerControl Class

SchedulerControl Members

DevExpress.XtraScheduler Namespace