Skip to main content

SchedulerControl.PrepareDragData Event

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.v24.2.dll

Declaration

public event PrepareDragDataEventHandler PrepareDragData

Event Data

The PrepareDragData event's data class is DevExpress.XtraScheduler.PrepareDragDataEventArgs.

Remarks

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.

Example

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.

View Example

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;
}
See Also