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

Paste contents into focused cell, not first cell in row

4 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 20 May 2011, 08:14 PM
I have a grid set with SelectionMode="Multiple".

If the user is on a cell that holds a time value, and copies that to the clipboard, then uses the arrow key to move down one row, he is now on the time cell right below. When he pastes, nothing appears to happen. He has to click in the cell first. I think what is actually happening is that the grid is trying to paste the contents into the first cell in the row. I can see in the demo that if the grid's selection unit is set to cell instead of row, then pasting works "normally".

How do I fix this? I tried handling the PastingCellClipboardContent event, but couldn't see how to redirect the paste towards the cell that actually has the focus.

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 24 May 2011, 09:16 AM
Hello James,

 In PastingCellClipboardContent event, you could find the currently focused cell using RadGridView.CurrentCellInfo. For example if your time field is "Established", you may use the following logic in your case:

private void clubsGrid_PastingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
{
       if (e.Cell.Column.UniqueName == "Established")
       {
            Club currentSelectedItem = (sender as RadGridView).CurrentCellInfo.Item as Club;
            Club copiedSelectedItem = e.Cell.Item as Club;
            currentSelectedItem.Established = copiedSelectedItem.Established;
       }
}

I have prepared a sample project. Could you please review it and if this is not the case, could you change it appropriately and send it in a separate support ticket? Could you please as well specify what the demo that you are referencing is? This way we would suggest you an approach, appropriate for your case.

All the best,
Didie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 24 May 2011, 04:15 PM
Thanks, but I prefer to have a generic workaround to what I perceive (to be honest) as incorrect behavior in the grid. Think about the symmetry here (or rather, lack thereof). With the cell having the focus in the first row, the copy operation copies that cell's contents to the clipboard. With the same cell on the next row having the focus, paste should paste the clipboard's contents into that cell. But it doesn't.

Let's say I have a column "Call Time", and on row 0 it has a value of 9:00 AM. I copy that, and use the arrow key to move down one row and paste. In the PastingCellClipboardContent event I can see that e.Value is "9:00 AM". So that's what I need. I need to paste that directly into the current cell on row 1 - not the first cell, but the current one, which is the call time cell for that row. Can you modify the code you gave me to do that? I can't see how to do it, without hard-coding a case for every column, or perhaps using reflection, neither of which I should have to do. I really shouldn't have to be handling this event at all, in my opinion.
0
Milan
Telerik team
answered on 25 May 2011, 01:12 PM

Hello James,

Let me provide you with more information about our copy/paste mechanism. When SelectionUnit is FullRow the grid will copy and paste whole rows. Contrary, when SelectionUnit is Cell the grid will paste and copy only selected cells. Also, when pasting, the pasting operation begin from the first selected unit. 

I believe that the confusion come from the fact that Multiple selection mode is used. When you use navigation in conjunction with Multiple selection, selection is not modified by navigation - for example, moving to the next row will not select the next row. 

Having this in mind, when you copy the first cell and then move to the cell below it, the latter cell will not become selected. This means that if you try to paste some content the pasting will begin from the first selected cell, not from the one that currently has focus.

This behavior is consistent no matter what mode is being used. Have you considered using Extended selection mode?



All the best,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 27 May 2011, 05:21 PM
I think the real problem here is that the Telerik grid tries to paste rows. I don't think this is useful. It's useful to copy rows, but users are not usually going to need to paste entire rows. They want to paste into whatever cell has the focus. I tried this with another vendor's grid that I have used in the past, and that grid works as I would expect.

When I was observing the cell text being pasted only into the first column, of course what I was seeing was Telerik assuming that the clipboard contents contained an entire row (or rows), then pasting into the first column, then stopping because there is no additional data following a space or a tab, as there would be had I just copied an entire row's contents into the clipboard.

I've gone ahead and implemented a hard-coded workaround along the lines of what you provided.

Thanks
Jim
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
James
Top achievements
Rank 1
Milan
Telerik team
Share this question
or