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

Copy cell instead of row

6 Answers 579 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 16 Aug 2012, 04:21 PM
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

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Aug 2012, 07:16 AM
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.

0
Michael
Top achievements
Rank 1
answered on 17 Aug 2012, 01:59 PM
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)

0
Dimitrina
Telerik team
answered on 17 Aug 2012, 02:00 PM
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.

0
Michael
Top achievements
Rank 1
answered on 17 Aug 2012, 02:32 PM
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");
        }
    }
}


0
Dimitrina
Telerik team
answered on 17 Aug 2012, 02:45 PM
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.

0
Gavin
Top achievements
Rank 1
answered on 12 Aug 2016, 02:33 PM

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

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Michael
Top achievements
Rank 1
Gavin
Top achievements
Rank 1
Share this question
or