Drag & Drop Appointments
- 4 minutes to read
Events
Starting from v19.1, the SchedulerControl includes multiple events designed for customizing drag & drop behavior. The following diagram demonstrates all drag & drop stages and their corresponding events:
The SchedulerControl.StartAppointmentDrag event occurs when a user starts dragging selected Scheduler appointments. The following three events occur repeatedly while a user is dragging appointments within a Scheduler view:
- SchedulerControl.QueryContinueAppointmentDrag
- Raised repeatedly while the user drags appointments within a Scheduler’s view and allows you to cancel the drag-drop operation.
- SchedulerControl.DragAppointmentOver
- Raised repeatedly while the user drags appointments within a Scheduler’s view.
- SchedulerControl.GiveAppointmentDragFeedback
- Raised repeatedly while the user drags appointments within a Scheduler’s view and allows you to specify the feedback.
Set the SchedulerControl.QueryContinueAppointmentDrag‘s Action
property to Drop
to raise the SchedulerControl.DropAppointment event that allows you to customize drop operation behavior.
If the SchedulerControl.QueryContinueAppointmentDrag‘s Action
property is set to Cancel
, the SchedulerControl.DropAppointment event does not occur.
The SchedulerControl.CompleteAppointmentDragDrop event occurs when a user drops an appointment dragged within boundaries of the same Scheduler.
When a user starts dragging an object outside Scheduler boundaries, the StartAppointmentDragFromOutside event occurs instead of SchedulerControl.StartAppointmentDrag. Only the SchedulerControl.DragAppointmentOver event occurs repeatedly while the user drags appointments within a view. The SchedulerControl.CompleteAppointmentDragDrop event never occurs for external objects dragged into the Scheduler.
Warning
SchedulerControl.AppointmentDrag
and SchedulerControl.AppointmentDrop
events are obsolete. If you try to handle either of these events in addition to any events listed above in the same project, the SchedulerControl throws an exception.
Limit Drag & Drop Operations
The SchedulerControl provides access to the following events and properties designed to limit drag & drop operations:
Property | Description |
---|---|
SchedulerControl.AllowAppointmentDrag | Specifies if users can drag and drop appointments between time slots or dates. You can handle the SchedulerControl.CustomAllowAppointmentDrag event to override this global behavior. |
SchedulerControl.AllowAppointmentDragBetweenResources | Allows you to prevent users from dragging appointments between resource areas. |
SchedulerControl.AllowAppointmentConflicts | Allows you to prevent users from dragging appointments to a time interval occupied by another appointment. |
SchedulerControl.AppointmentDragMode | Specifies how an appointment fits into target time cells when dragged to another time interval. |
SchedulerControl.KeepResourceDistanceOnAppointmentDrag | Specifies whether the Scheduler puts all dragged appointments into the same target resource or tries to keep their original distribution. |
SchedulerControl.ScrollOnDrag | Specifies if a user can scroll the scheduler view area by dragging an appointment to a viewport border. |
The SchedulerControl.CustomAllowAppointmentDrag event fires when a user attempts to drag an appointment to another time interval. Handle this event to specify a condition when an appointment drag operation is allowed. If you did not define such a condition, the SchedulerControl.AllowAppointmentDrag property manages the appointment drag permission if the SchedulerControl.CustomAllowAppointmentDrag event is raised.
The SchedulerControl.CustomAllowAppointmentDragBetweenResources event fires when a user attempts to drag an appointment. Handle this event to specify a condition when a user can drag an appointment to another resource area. If you do not define such a condition, the SchedulerControl.AllowAppointmentDragBetweenResources property specifies if users can drag appointments.
Drag & Drop Appointments Between Schedulers in Different Applications
You can implement drag & drop functionality between two standalone applications that host bound SchedulerControl instances. This implementation does not require the BinaryFormatter compatibility package (deprecated in .NET 9).
Follow steps below to enable users to drag appointments from a SchedulerControl in the first application and drop them onto a SchedulerControl in the second application, as long as both controls use the same underlying data model (for example, an Item
class):
Step 1. Define a Shared Data Format
Both applications must define the same format string to identify dragged data:
string itemsJsonFormat = "JSON_" + typeof(IEnumerable<Item>).FullName;
Ensure that both applications reference the same Item
class definition (for example, from a shared project or assembly).
Step 2. Start Drag
In the first application, handle the StartAppointmentDrag event and serialize dragged appointments:
void OnStartAppointmentDrag(object sender, StartAppointmentDragEventArgs e) {
var sources = e.SourceAppointments
.Select(x => x.SourceObject)
.OfType<Item>()
.ToList();
var serialized = JsonSerializer.Serialize(sources);
e.Data.SetData(itemsJsonFormat, serialized);
}
The StartAppointmentDrag event handler demonstrated above serializes original Item
objects to a JSON string and attaches them to the drag DataObject
.
Step 3. Accept Drop
In the second application, handle the StartAppointmentDragFromOutside event and deserialize dropped appointments:
void OnStartAppointmentDragFromOutside(object sender, StartAppointmentDragFromOutsideEventArgs e) {
if (e.DragAppointments.Count != 0)
return;
if (!e.Data.GetDataPresent(itemsJsonFormat))
return;
var json = e.Data.GetData(itemsJsonFormat) as string;
e.SourceObjects = JsonSerializer.Deserialize<IEnumerable<Item>>(json);
}
The SourceObjects
property must contain custom objects required to generate new appointments in the target SchedulerControl.