RadScheduler support drag and drop from another control, such as dragging appointment subjects from a RadListControl, or appointment date from RadGridView. In order to use this feature, we will need to find the scheduler cell when the item is dropped onto the scheduler surface. Once you have the scheduler cell you can get the date and create an appointment for it.
In this example we will use RadDropDownList and will also make the appointment recur for three days.
In the RadScheduler DragDrop event handler you need to get the location of the mouse and convert it to a point that the scheduler can use to get the cell element underneath the mouse. This MonthCellElement is passed to a private method GetCellAppointment() that we will write next.
Copy[C#] Drop to the month cell element
private void radScheduler1_DragDrop(object sender, DragEventArgs e)
{
Point point = this.radScheduler1.PointToClient(new Point(e.X, e.Y));
DayViewAppointmentsTable table = (this.radScheduler1.SchedulerElement.ViewElement as SchedulerDayViewElement).DataAreaElement.Table;
SchedulerCellElement schedulerCell = SchedulerUIHelper.GetCellAtPoint(point, table.Children);
if (schedulerCell != null)
{
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
if (dragObject != null)
{
this.radScheduler1.Appointments.BeginUpdate();
Appointment appointment = CreateAppointment(schedulerCell.Date, dragObject);
this.radScheduler1.Appointments.Add(appointment);
this.radScheduler1.Appointments.EndUpdate();
}
}
this.mouseDownPosition = Point.Empty;
this.isDragging = false;
}
Copy[VB.NET] Drop to the month cell element
Private Sub radScheduler1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
Dim point As Point = Me.radScheduler1.PointToClient(New Point(e.X, e.Y))
Dim table As DayViewAppointmentsTable = (TryCast(Me.radScheduler1.SchedulerElement.ViewElement, SchedulerDayViewElement)).DataAreaElement.Table
Dim schedulerCell As SchedulerCellElement = SchedulerUIHelper.GetCellAtPoint(point, table.Children)
If schedulerCell IsNot Nothing Then
Dim dragObject As DragObject = TryCast(e.Data.GetData(GetType(DragObject)), DragObject)
If dragObject IsNot Nothing Then
Me.radScheduler1.Appointments.BeginUpdate()
Dim appointment As Appointment = CreateAppointment(schedulerCell.Date, dragObject)
Me.radScheduler1.Appointments.Add(appointment)
Me.radScheduler1.Appointments.EndUpdate()
End If
End If
Me.mouseDownPosition = point.Empty
Me.isDragging = False
End SubThe helper method CreateAppointment() creates an appontment starting at the cell where the RadListDataItem is dropped. This appointment gets its data from the dragged RadListDataItem.
Copy[C#] Creating an appointment
private Appointment CreateAppointment(DateTime currentDate, DragObject dragObject)
{
Appointment appointment = new Appointment();
DateTime startDate = currentDate;
DateTime endDate = currentDate.AddHours(1);
switch (dragObject.Status)
{
case AppointmentFields.Summary:
appointment.Summary = dragObject.Values[dragObject.Status] as string;
break;
case AppointmentFields.Row:
appointment.Summary = dragObject.Values[AppointmentFields.Summary] as string;
appointment.Description = dragObject.Values[AppointmentFields.Description] as string;
appointment.BackgroundId = (int)dragObject.Values[AppointmentFields.Background];
appointment.StatusId = (int)dragObject.Values[AppointmentFields.Status];
appointment.Location = dragObject.Values[AppointmentFields.Location] as string;
startDate = (DateTime)dragObject.Values[AppointmentFields.Start];
endDate = (DateTime)dragObject.Values[AppointmentFields.End];
TimeSpan range = endDate - startDate;
endDate = currentDate + range;
startDate = currentDate;
break;
}
appointment.Start = startDate;
appointment.End = endDate;
return appointment;
}
Copy[VB.NET] Creating an appointment
Private Function CreateAppointment(ByVal currentDate As Date, ByVal dragObject As DragObject) As Appointment
Dim appointment As New Appointment()
Dim startDate As Date = currentDate
Dim endDate As Date = currentDate.AddHours(1)
Select Case dragObject.Status
Case AppointmentFields.Summary
appointment.Summary = TryCast(dragObject.Values(dragObject.Status), String)
Case AppointmentFields.Row
appointment.Summary = TryCast(dragObject.Values(AppointmentFields.Summary), String)
appointment.Description = TryCast(dragObject.Values(AppointmentFields.Description), String)
appointment.BackgroundId = CInt(Fix(dragObject.Values(AppointmentFields.Background)))
appointment.StatusId = CInt(Fix(dragObject.Values(AppointmentFields.Status)))
appointment.Location = TryCast(dragObject.Values(AppointmentFields.Location), String)
startDate = CDate(dragObject.Values(AppointmentFields.Start))
endDate = CDate(dragObject.Values(AppointmentFields.End))
Dim range As TimeSpan = endDate.Subtract(startDate)
endDate = currentDate.Add(range)
startDate = currentDate
End Select
appointment.Start = startDate
appointment.End = endDate
Return appointment
End Function