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

Problems with Paste command when row is in edit mode

1 Answer 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 11 May 2011, 12:26 AM
Hi,

I have a GridView with the following properties:
SelectionMode="Extended" and SelectionUnit="Cell"

The following "paste" code works great when the grid is NOT in edit mode:
private void Paste_Click(object sender, RoutedEventArgs e)
{
    var pasteCommand = RadGridViewCommands.Paste as RoutedUICommand;
    pasteCommand.Execute(null, this.radGridView);
}

However, if a user has double clicked a cell for edit mode and tries to paste, the paste command does not function properly.  What seems to be happening is the following sequence: 
  1. clicking paste takes the grid out of edit mode
  2. grid scrolls to top record and focus is set to first cell
  3. paste occurs on first row, first cell rather than where the user expected to paste content

The above paste command needs to work regardless of whether or not the grid is in editing mode.  Please advise.

Thanks,
Brian

1 Answer, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 11 May 2011, 06:38 AM
Hello Brian,

 Pasting starts with the first selected cell. However, in edit mode no cells are selected. If no cells are selected, pasting begins at the first cell of the RadGridView.

 You will need to handle the Pasting event and do the following:
  • Save the value of the CurrentCellInfo property of the RadGridView to a field. This is the cell that is currently being edited.
  • Call CommitEdit() on RadGridView to manually exit the edit operation.
  • Add the saved CellInfo to the SelectedCells property of RadGridView (make sure only this cell is selected)
 RadGridView will then proceed to paste starting from the selected cell.

 If you like, you can handle the Pasted event where you can call BeginEdit() on the RadGridView to return the user in edit mode. Make sure that the CurrentCellInfo property of the RadGridView points to the GridViewCellInfo object you saved at the beginning of the Pasting event.

 I hope this helps.

Greetings,
Yavor Georgiev
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
Tags
GridView
Asked by
Brian
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Share this question
or