Raddatetimepicker copy & paste

2 posts, 0 answers
  1. Dra Graca Melo
    Dra Graca Melo avatar
    5 posts
    Member since:
    Dec 2009

    Posted 13 Oct 2010 Link to this post

    I'me using Raddatetimepicker, but users can't copy and paste values inside it.

    Can you tell me why?

    Thank you.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 13 Oct 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top