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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to prevent the grid cell from allowing paste in WinForms GridControl?

Platform: WinForms |
Control: GridControl
Tags: copypaste

Handle the PasteCellText event

You have to handle the PasteCellText event of the GridControl and cancel the event that prevents the cells from allowing paste. This event is not triggered when the current cell is in Edit mode.


//In Form_Load
this.gridControl1[1, 2].Text = "HI";
this.gridControl1.ActivateCurrentCellBehavior = GridCellActivateAction.DblClickOnCell;
//using the PasteCellText Event
void gridControl1_PasteCellText(object sender, Syncfusion.Windows.Forms.Grid.GridPasteCellTextEventArgs e)
    //Row 3 as prevent from paste
    if (e.RowIndex == 3)
        e.Cancel = true;


' In Form_Load
Me.gridControl1(2, 2).Text = "HI"
Me.gridControl1.ActivateCurrentCellBehavior = GridCellActivateAction.DblClickOnCell
Private Sub gridControl1_PasteCellText(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPasteCellTextEventArgs)
' Row 3 as prevent from paste
    If e.RowIndex = 3 Then
        e.Cancel = True
End If
End Sub

When you want to avoid pasting into a cell that is in Edit mode, you can make use of the CurrentCellControlKeyMessage event. In the following code, the paste operation is specified by the shortcut key, Ctrl+V.


void gridControl1_CurrentCellControlKeyMessage(object sender, GridCurrentCellControlKeyMessageEventArgs e)
    Keys keyCode = (Keys)((int)e.Msg.WParam) & Keys.KeyCode;
    //Condition for Ctr+V keys
    if ((Control.ModifierKeys & Keys.Control) != 0 && keyCode == Keys.V )
        GridCurrentCell cc = this.gridControl1.CurrentCell;
        //set the row 3 as prevent from  paste
        if(cc.RowIndex == 3)
            e.Handled = true;
        e.Result = true;


Private Sub gridControl1_CurrentCellControlKeyMessage(ByVal sender As Object, ByVal e As GridCurrentCellControlKeyMessageEventArgs)
    Dim keyCode As Keys = CType(CInt(Fix(e.Msg.WParam)), Keys) And Keys.KeyCode
    If (Control.ModifierKeys And Keys.Control) <> 0 AndAlso keyCode = Keys.V Then
        ' set the row 3 as prevent from allow paste
        Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
        If cc.RowIndex = 3 Then
            e.Handled = True
        End If
    e.Result = True
    End If
End Sub


C#: Preventing_from_Pate

VB: Preventing_from_Paste

Reference link: https://help.syncfusion.com/windowsforms/grid-control/copy-and-paste#events

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile