sfDataGrid1.AllowEditing = false It will still be affected by pasting

  sfDataGrid1.AllowEditing = false 



It will still be affected by pasting


CTRL +V   

Will change value

How to shield?


1 Reply

SB Sweatha Bharathi Syncfusion Team July 26, 2023 01:53 PM UTC

Hi yu ma ,


In the SfDataGrid, we have provided support for pasting even when the AllowEditing property is set to false. To prevent pasting when AllowEditing is false, you can use the PasteContent event. If you need to control pasting for entire rows, you can use the PasteContent event. Similarly, if you need to control pasting at the cell level, you can use the PasteCellContent event.

For more details and implementation examples, please refer to the documentation provided below:

https://help.syncfusion.com/windowsforms/datagrid/clipboardoperations#cancel-paste-operation


Code Snippet :


private void SfDataGrid_PasteContent(object sender, CutCopyPasteEventArgs e)

        {

            if ((e.OriginalSender as SfDataGrid).AllowEditing == false)

                e.Cancel = true;

        }



We have provided the sample for your reference , kindly review the sample and let us know if you have any further concerns.




Attachment: Sample_1b13cfb9.zip

Loader.
Up arrow icon