How to do a DragAndDrop of ListView items into SfSchedule Control?
Schedule provides a support for drag-drop of items from ListView. This section briefly explains you about this support by creating an application to represent, drag-drop functionality in Schedule control from the ListView. You can store your appointments in ScheduleAppointmentCollection. GridView contains items that display the appointments with its Subject and Notes properties. You can drag and drop ListViewItem into corresponding schedule area. As of now the list view items must be of ScheduleAppointment type in order to drop the item in SfSchedule control.
Figure 1: ListView items DragAndDrop into SfSchedule
Description
In this application stored appointments are displayed in GridView items. You can DragAndDrop the appointments into the schedule area as per your convenient time. To achieve this requirement, you can consider the following three areas.
- Store appointments
- Drag appointments
- Drop appointments
Store Appointments
Figure 2: Stored appointments in GridView
Appointments are stored in ScheduleAppointmentCollection. Appointment type must be in ScheduleAppointment type. The following code example explains you how to store the schedule appointment collection.
C#
private ScheduleAppointmentCollection GetAppointments() { ScheduleAppointmentCollection app = new ScheduleAppointmentCollection(); app.Add(new ScheduleAppointment() { StartTime = DateTime.Now.Date.AddHours(2), EndTime = DateTime.Now.Date.AddHours(4), AppointmentBackground = new SolidColorBrush(Colors.Green), Subject = "Business Meeting", Notes = "Consulting firm laws with business advisers" }); app.Add(new ScheduleAppointment() { StartTime = DateTime.Now.Date.AddDays(1).AddHours(6), EndTime = DateTime.Now.Date.AddDays(1).AddHours(8), AppointmentBackground = new SolidColorBrush(Colors.Orange), Subject = "Conference", Notes = "Attend 2nd international conference about WinRT Development" }); app.Add(new ScheduleAppointment() { StartTime = DateTime.Now.Date.AddDays(-2).AddHours(4), EndTime = DateTime.Now.Date.AddDays(-2).AddHours(6), AppointmentBackground = new SolidColorBrush(Colors.LightPink), Subject = "Medical check up", Notes = "Brooklyn medical university. Dental checkup" }); return app; }
Drag appointments
Figure 3: Dragged appointment from ListVIew Items.
While Dragging, you can use DragItemsStarting event of GridView, to set the ScheduleAppointment by adding the dragged item in e.Data.Properties. The following code example explains you how to perform dragging event.
C#
private void gridview_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { ScheduleAppointment app = ((ScheduleAppointment)e.Items[0]); e.Data.Properties.Add("App", app); this.selectedapp = app; }
Drop appointments
Figure 4: Dropped appointments from ListView items
While dropping the schedule appointment, you can handle schedule drop event in order to get the appointment and to remove the respective item from the GridView. The following code example explains how to perform schedule drop event.
C#
void schedule_Drop(object sender, DragEventArgs e) { if (this.selectedapp != null) { dc.AppCollection.Remove(selectedapp); } }
Figure 5: DragAndDrop appointments From ListView to SfSchedule.