We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Trouble with cut/copy/paste

Hi,

When I copy one cell and paste it, it puts the cell into edit mode, and hence if I press enter it raises the CurrentCellAcceptedChanges event. The PasteCellText event is never raised.

On the other hand, if I copy multiple cells and paste, then the PasteCellText event is raised for each cell.

The 2nd behavior is what I'm looking for, so that by handling the PasteCellText event I can validate and also store the updated cell values for each cell, I also do not want the cell to be in edit mode after a paste (Excel does not do this).

1) Could you please tell me how I can avoid the 1st behavior? I have attached a sample.
2) If I want to perform similar functionality on the Cut (ie store in my data "blank" for the cells that were cut), the only place I can find to do this is the ClipboardCut event. Is this correct? I guess I would have to iterate through all the selected cells on the grid and set their values in my data to "blank". However, this seems a bit risky because it is not being done simultaneously with the cut. Is there any event which is raised as each cell is being cut (ie similar to PasteCellText)? Or is the only solution to store values into the clipboard myself and do everything manually?

Thanks.




Syncfusion.zip

4 Replies

AD Administrator Syncfusion Team April 2, 2008 05:02 PM UTC

Hi Omar,

To fire PasteCellText for single cell you need to use external pasting by use of "TextDataExchange.PasteTextRowCol" method in
CurrentCellKeyDown event. The code's are below

Private Sub GridControl1_CurrentCellKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GridControl1.CurrentCellKeyDown
If e.KeyCode = Keys.V AndAlso e.Modifiers = Keys.Control Then
Dim _strText As String = TryCast(Clipboard.GetData(DataFormats.Text), String)
If _strText.Split(New String() {Constants.vbTab, Environment.NewLine}, StringSplitOptions.None).Length = 1 Then
e.Handled = True
Dim _grid As GridControl = TryCast(sender, GridControl)
Dim _cc As GridCurrentCell = _grid.CurrentCell
_grid.Model.TextDataExchange.PasteTextRowCol(_cc.RowIndex, _cc.ColIndex, _strText)
End If
End If
End Sub

And also we have modified your sample refer that and let me know if you need further assistance.

Sample:

http://websamples.syncfusion.com/Samples/Grid.Windows/F72717/main.htm





OM Omar April 3, 2008 01:08 PM UTC

Thanks this works. But when I am doing a Cut, I also do not want the cell to go into Edit mode (if only 1 cell is selected). How would I go about preventing this? I would just like the cell to clear instead of going into edit mode.

Thanks.



AD Administrator Syncfusion Team April 3, 2008 09:07 PM UTC

Hi Omar,

Thank you for your update.

To prevent Edit mode of the Gridcell when you are pressed ctrl+x, you need to handle CurrentCellKeyDown event. In that event handler, you need to follow below steps.

1.Cancel the default Cut method by using //e.Handled = True.
2.To fire the Cut method manually by use of "CutPaste.Cut()" method.
3.Cancel the Edit mode of current Gridcell by use of "EndEdit()" method

Below are the codes that show this task.

Private Sub gridControl1_CurrentCellKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
If e.KeyCode = Keys.X AndAlso e.Modifiers = Keys.Control Then
e.Handled = True
Me.gridControl1.Model.CutPaste.Cut()
Me.gridControl1.CurrentCell.EndEdit()
End If

End Sub

Please Let me know if you need further assistance.

Best regards,
Johnson



OM Omar April 4, 2008 07:55 PM UTC

This can work, but it seems a little bit odd because on one hand when you cut one cell, all the cell changing events are raised (startedit, validating, etc), but when you cut multiple cells none of these events are raised (ie for each cell).

Thanks for your help


Loader.
Live Chat Icon For mobile
Up arrow icon