Copy cell instead of row

7 posts, 0 answers
  1. Michael
    Michael avatar
    23 posts
    Member since:
    Jun 2012

    Posted 16 Aug 2012 Link to this post

    Hello,

    Is it possible to change default behavior of RadGridView so when user press Ctrl+C it is copy current cell value into clipboard not the entire row?

    Thanks
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Aug 2012 Link to this post

    Hello,

    If you set the SelectionMode to be Cell, then when user press "Ctrl+C" the content of the current selected cell will be copied. 

    Is this suitable for your scenario?

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    23 posts
    Member since:
    Jun 2012

    Posted 17 Aug 2012 Link to this post

    SelectionMode  enum contains only Extended, Multiple or Single. There is no Cell mode available.

    Also I need to be able to select  the whole row not single cells (actually my Selection mode is Extended)

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Aug 2012 Link to this post

    Hi,

     I am sorry, I meant the SelectionUnit property.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Michael
    Michael avatar
    23 posts
    Member since:
    Jun 2012

    Posted 17 Aug 2012 Link to this post

    As I said - SelectionUnit = Cell is not good for my scenario as Users need to select multiple rows (whole rows not cells).
    I think I am going to set ClipboardCopyMode to None which will disable default copying at all and will hook CTRL+C keyboard gesture to my custom method that will grab the current cell value and put it in Clipboard. I already have the method. It is being called from context menu for the grid.

    void miCopyCell_Click(object sender, RoutedEventArgs e)
    {
        if (this.CurrentCell == null)
        {
            MessageBox.Show("No cell has been selected.");
            return;
        }
     
        var text = this.CurrentCell.Value.ToString();
        try
        {
            Clipboard.SetText(text);
        }
        catch (System.Runtime.InteropServices.COMException)
        {
            System.Threading.Thread.Sleep(0);
            try
            {
                Clipboard.SetText(text);
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                MessageBox.Show("Can't Access Clipboard");
            }
        }
    }


  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Aug 2012 Link to this post

    Hi,

    Thank you for this remarks. You are right, you should implement your own copy functionality in that scenario.

    Please keep in mind that this key combination is handled internally as RadGridView does provide support for copy-paste functionality and the corresponding shortcuts for it. 

    What you could do is to add a handler for KeyDown event as follows:

    public MainPage()
            {
                InitializeComponent();
                this.AddHandler(RadGridView.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);
            }
      
            private void OnKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
                {
                    // your logic
                }
            }


    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Gavin
    Gavin avatar
    8 posts
    Member since:
    Mar 2013

    Posted 12 Aug Link to this post

    Found an easier way to do it.  All you have to do is attach an event handler on the radgridview for the CopyingCellClipboardContent event and check if the e.Cell == the currentcellinfo otherwise just sent e.Cancel to true

Back to Top
UI for WPF is Visual Studio 2017 Ready