Item Dragging Context in the ItemChanging event in Scheduler
18 Nov 20183 minutes to read
This feature provides support to detect the dragging context when an item is dropped in the schedule part or calendar part. It also enables you to cancel specific items as needed through the ItemChanging event.
Use case scenario
In the ItemChanging event, through the ItemDragHitContext enumeration, you can detect the dragging context (Schedule or Calendar) and cancel specific items as needed.
Property
| Property | Description | Data Type |
|---|---|---|
| ItemDragHitContext | Specifies where the mouse is during an appointment drag in a week or month view. | enum |
Event
| Event | Parameters | Description |
|---|---|---|
| ItemChanging | object sender, ScheduleAppointmentCancelEventArgs e | Occurs after an IScheduleAppointment is modified. |
Sample link
You can get the schedule sample from the following online location:
http://samples.syncfusion.com/windowsforms
Adding drag-context detection to an application
The following steps help you to get the target part in the Schedule control while dragging:
- Create a Schedule control enabled sample application.
- Add appointments in that schedule grid.
- Hook the
ItemChangingevent.
using Syncfusion.Windows.Forms.Schedule;
this.scheduleControl1.ItemChanging += new ScheduleAppointmentChangingEventHandler(scheduleControl1_ItemChanging);Imports Syncfusion.Windows.Forms.Schedule
AddHandler scheduleControl1.ItemChanging, AddressOf scheduleControl1_ItemChangingGet the drag hit context with the following code.
void scheduleControl1_ItemChanging(object sender, ScheduleAppointmentCancelEventArgs e)
{
if (e.Action == ItemAction.ItemDrag)
{
Console.WriteLine("Dropped Area :" + e.ItemDragHitContext);
}
}Private Sub scheduleControl1_ItemChanging(ByVal sender As Object, ByVal e As ScheduleAppointmentCancelEventArgs)
If e.Action = ItemAction.ItemDrag Then
Console.WriteLine("Dropped Area :" + e.ItemDragHitContext.ToString())
End If
End SubYou can cancel the dropped item using the ItemDragHitContext property.
void scheduleControl1_ItemChanging(object sender, ScheduleAppointmentCancelEventArgs e)
{
if (e.ItemDragHitContext == ItemDragHitContext.Calendar)
e.Cancel = true;
}Private Sub scheduleControl1_ItemChanging(ByVal sender As Object, ByVal e As ScheduleAppointmentCancelEventArgs)
If e.ItemDragHitContext = ItemDragHitContext.Calendar Then
e.Cancel = True
End If
End Sub