Skip to main content Skip to footer

How to copy and paste appointments in C1Scheduler for WinForms

C1Schedulder for WinForms supports dragging and dropping appointments within one scheduler control. But what if you want to extend this feature to support the keyboard and clipboard shortcuts? The requirement may range from simply copying Appointments from one day to other in the same Scheduler, to performing the copy-paste operations across two Scheduler controls. This sample meets both of those requirements.

Copying the Appointments

We can allow the users to copy single and multiple Appointments in order to meet the requirements. Multiple selection of Appointments in Scheduler is performed by pressing the shift key and then selecting the desired Appointments.

The main logic behind copying the Appointments is implemented in KeyDown event of Scheduler. When the "Ctrl+C" keys are pressed, all the selected Appointments are stored in an array using the SelectedAppointments property. They can be retrieved one by one from the array while pasting.

Private Sub C1Schedule1_KeyDown(sender As Object, e As KeyEventArgs)  
    If (e.Modifiers = Keys.Control And e.KeyCode = Keys.C) Then  
        If (C1Schedule1.SelectedAppointments.Count > 0) Then  
            count = C1Schedule1.SelectedAppointments.Count  
            For i As Integer = 0 To count - 2  
                dayinterval(i) = DateDiff(DateInterval.Day, C1Schedule1.SelectedAppointments(i).Start.Date, C1Schedule1.SelectedAppointments(i +  ).Start.Date)  
            Next  
            For k As Integer = 0 To count - 1  
                applist(k) = C1Schedule1.SelectedAppointments(k).Copy()  
            Next  
        End If  
    End If  
End Sub 

Now the "applist" array collection will contain all the selected Appointments. When the Appointments are copied and stored in an array, the difference of every date (dayinterval) with its successor is also calculated using DateDiff.aspx) method of Microsoft.VisualBasic.DateAndTime class and stored in another array. The reason being, the same difference of dates can be added in between pasting the Appointments.

Pasting the Appointments

The next step is to paste the copied Appointments from "applist" array to Scheduler. The array is traversed to retrieve the Appointments one by one so as to add them in the Appointment storage of the Scheduler. The next Appointment to be pasted will add the date difference to its start date, so that the same difference between the dates can be maintained.

Private Sub C1Schedule1_KeyDown(sender As Object, e As KeyEventArgs)  
    If (e.Modifiers = Keys.Control And e.KeyCode = Keys.V) Then  
        Dim selecteddate As Date = C1Schedule1.SelectedInterval.Start  
        For i As Integer = 0 To count - 1  
            Dim appnew1 As Appointment = New Appointment()  
            appnew1.Body = appList(i).Body  
            appnew1.Subject = appList(i).Subject  
            appnew1.Location = appList(i).Location  
            appnew1.Start = New DateTime(selecteddate.Year, selecteddate.Month, selecteddate.Day, appList(i).Start.Hour, appList(i).Start.Minute, appList(i).Start.Second)  
            appnew1.Duration = applist(i).Duration  
            appnew1.BusyStatus = applist(i).BusyStatus  
            appnew1.Label = applist(i).Label  
            appnew1.AllDayEvent = applist(i).AllDayEvent  
            C1Schedule1.DataStorage.AppointmentStorage.Appointments.Add(appnew1)  
            selecteddate = selecteddate.AddDays(dayinterval(i))  
        Next  
    End If  
End Sub 

The same approach can be implemented in another Scheduler by handling its KeyDown event and using the same "applist" and "dayinterval" array collections.