New to Telerik UI for WinForms? Download free 30-day trial

Copy/Paste custom fields in RadScheduler

Environment

Product Version Product Author
2019.2.618 RadScheduler for WinForms Desislava Yordanova

Description

When you have a custom implementation for the Appointment class, e.g. you extended the Appointment class with an Email field and try to copy/paste it, only the content of the basic Appointment class are being transferred. A common requirement is to copy/paste the Email field as well.

Solution

In order to copy/paste a custom field (e.g. Email) in the Appointment, you can store the value of the selected object in the AppointmentCopying event and assign the stored value in the AppointmentAdded event. Here is demonstrated a sample approach:


 private void radScheduler1_AppointmentsCopying(object sender, SchedulerClipboardEventArgs e)
{
    this.radScheduler1.Tag = ((AppointmentWithEmail)e.Appointments[0]).Email;
}

private void radScheduler1_AppointmentAdded(object sender, AppointmentAddedEventArgs e)
{
    if (this.radScheduler1.Tag + "" != "")
    {
        ((AppointmentWithEmail)e.Appointment).Email = this.radScheduler1.Tag.ToString();
    }
    this.radScheduler1.Tag = null;
}                        

If you need to have full control on the copy/paste operations in RadScheduler, you can create a derivative of the SchedulerInputBehavior, override its HandleKeyDown method and execute the desired logic when the Control key is pressed in combination with Keys.V or Keys.C:


 public class CustomSchedulerInputBehavior : SchedulerInputBehavior
{
    public CustomSchedulerInputBehavior(RadScheduler scheduler) : base(scheduler)
    {
    }

    public override bool HandleKeyDown(KeyEventArgs args)
    {
        if (args.Modifiers == Keys.Control)
        {
            switch (args.KeyCode)
            {
                case Keys.C:
                    this.Scheduler.Copy();
                    break;
                case Keys.X:
                    this.Scheduler.Cut();
                    break;
                case Keys.V:
                    this.Scheduler.Paste();
                    break;
            }
        }
        return false;
    }
}                       

Then, set the RadScheduler.SchedulerInputBehavior property to the custom behavior that you have:


 this.radScheduler1.SchedulerInputBehavior = new CustomSchedulerInputBehavior(this.radScheduler1);