windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-62c6838d.md
Fires when a user drags data items from another control or application, and allows you to create appointments based on the dragged data.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.dll
NuGet Package : DevExpress.Win.Scheduler
public event PrepareDragDataEventHandler PrepareDragData
Public Event PrepareDragData As PrepareDragDataEventHandler
The PrepareDragData event's data class is DevExpress.XtraScheduler.PrepareDragDataEventArgs.
The control allows users to drag an appointment within the control bounds to reschedule the appointment, and drag data from another control or application to create a new appointment based on the dragged data.
The PrepareDragData event fires when a user drags data into the control and allows you to create appointments based on the dragged data. You can use the following event arguments to get format-independent data passed from the source control/application and convert it to the scheduler data format:
The DataObject property — gets an IDataObject instance that contains data dragged from the source control. If you drag data from another control, you can create a DataObject instance and pass it to the DoDragDrop method.
The DragData property — gets or sets a SchedulerDragData object that contains appointments that should be created in the target scheduler. Use this property to create appointments based on data from the DataObject event argument.
The code below shows how to handle the SchedulerControl.PrepareDragData event to create appointments based on data passed from the source control.
The GetDragData method returns an IDataObject instance that contains dragged data rows. This object is then passed to the source control’s DoDragDrop method. In the PrepareDragData event handler, the DataObject event argument returns the data object. Use this data object to create new appointments. The DragData event argument allows you to pass appointments to the target scheduler control.
using DevExpress.XtraScheduler;
// This method creates data that is then passed to the source control's DoDragDrop method.
IDataObject GetDragData(GridView view) {
int[] selection = view.GetSelectedRows();
if (selection == null)
return null;
List<AppointmentExchangeData> exchangeList = new List<AppointmentExchangeData>();
int count = selection.Length;
for (int i = 0; i < count; i++) {
int rowIndex = selection[i];
exchangeList.Add(new AppointmentExchangeData() {
Subject = (string)view.GetRowCellValue(rowIndex, "Subject"),
LabelKey = (int)view.GetRowCellValue(rowIndex, "Severity"),
StatusKey = (int)view.GetRowCellValue(rowIndex, "Priority"),
Start = DateTime.MinValue,
Duration = TimeSpan.FromHours((int)view.GetRowCellValue(rowIndex, "Duration")),
Description = (string)view.GetRowCellValue(rowIndex, "Description"),
});
}
return new DataObject(DataFormats.Serializable, exchangeList);
}
// This event handler creates appointments based on data passed from the source control.
void OnSchedulerControlPrepareDragData(object sender, PrepareDragDataEventArgs e) {
object data = e.DataObject.GetData(DataFormats.Serializable);
AppointmentBaseCollection appointments = new AppointmentBaseCollection();
foreach (AppointmentExchangeData item in (IList)data) {
var apt = this.schedulerStorage.CreateAppointment(AppointmentType.Normal);
apt.Subject = item.Subject;
apt.Description = item.Description;
apt.Start = item.Start;
apt.Duration = item.Duration;
apt.LabelKey = item.LabelKey;
apt.StatusKey = item.StatusKey;
appointments.Add(apt);
}
SchedulerDragData schedulerDragData = new SchedulerDragData(appointments);
e.DragData = schedulerDragData;
}
Imports DevExpress.XtraScheduler
' This method creates data that is then passed to the source control's DoDragDrop method.
Private Function GetDragData(ByVal view As GridView) As IDataObject
Dim selection() As Integer = view.GetSelectedRows()
If selection Is Nothing Then
Return Nothing
End If
Dim exchangeList As New List(Of AppointmentExchangeData)()
Dim count As Integer = selection.Length
For i As Integer = 0 To count - 1
Dim rowIndex As Integer = selection(i)
exchangeList.Add(New AppointmentExchangeData() With {
.Subject = CStr(view.GetRowCellValue(rowIndex, "Subject")),
.LabelKey = CInt(Math.Truncate(view.GetRowCellValue(rowIndex, "Severity"))),
.StatusKey = CInt(Math.Truncate(view.GetRowCellValue(rowIndex, "Priority"))),
.Start = Date.MinValue,
.Duration = TimeSpan.FromHours(CInt(Math.Truncate(view.GetRowCellValue(rowIndex, "Duration")))),
.Description = CStr(view.GetRowCellValue(rowIndex, "Description"))
})
Next i
Return New DataObject(DataFormats.Serializable, exchangeList)
End Function
' This event handler creates appointments based on data passed from the source control.
Private Sub OnSchedulerControlPrepareDragData(ByVal sender As Object, ByVal e As PrepareDragDataEventArgs) Handles schedulerControl.PrepareDragData
Dim data As Object = e.DataObject.GetData(DataFormats.Serializable)
Dim appointments As New AppointmentBaseCollection()
For Each item As AppointmentExchangeData In DirectCast(data, IList)
Dim apt = Me.schedulerStorage.CreateAppointment(AppointmentType.Normal)
apt.Subject = item.Subject
apt.Description = item.Description
apt.Start = item.Start
apt.Duration = item.Duration
apt.LabelKey = item.LabelKey
apt.StatusKey = item.StatusKey
appointments.Add(apt)
Next item
Dim schedulerDragData As New SchedulerDragData(appointments)
e.DragData = schedulerDragData
End Sub
See Also