This is a migrated thread and some comments may be shown as answers.

Raddatetimepicker copy & paste

1 Answer 101 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Dra Graca Melo
Top achievements
Rank 1
Dra Graca Melo asked on 13 Oct 2010, 12:11 PM
I'me using Raddatetimepicker, but users can't copy and paste values inside it.

Can you tell me why?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 13 Oct 2010, 01:56 PM
Hello Dra Graca Melo ,

This behavior is not is not part of the standard RadDateTimePicker, or either the standard Microsoft DateTimePicker for that matter, but you can use something like this:
using System;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadDateTimePicker radDateTimePicker1;
 
    public Form1()
    {
        InitializeComponent();
 
        radDateTimePicker1 = new RadDateTimePicker();
        radDateTimePicker1.Dock = DockStyle.Top;
        this.Controls.Add(radDateTimePicker1);
 
        radDateTimePicker1.Value = DateTime.Now;
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        var textBox = new RadTextBox();
        textBox.Text = DateTime.Now.ToString();
        this.Controls.Add(textBox);
        textBox.Dock = DockStyle.Bottom;
 
        radDateTimePicker1.KeyUp += new KeyEventHandler(radDateTimePicker1_KeyUp);
    }
 
    void radDateTimePicker1_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Control)
        {
            if (e.KeyCode == Keys.V)
            {
                DateTime date;
 
                DateTime.TryParse(Clipboard.GetText(), out date);
                if (date != null)
                {
                    radDateTimePicker1.Value = date;
                }
            }
            else
            {
                if (e.KeyCode == Keys.C)
                {
                    Clipboard.SetText(radDateTimePicker1.Value.ToString(), TextDataFormat.UnicodeText);
                }
            }
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Dra Graca Melo
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or