SfDataGrid Validating Pasted Data

Hello,
I use the SfDataGrid validation (row based) functionality quite extensively. What I've realized just recently is my handler for the RowValidation event doesn't get called if the user should paste data into the grid control.
Do you have an example of how to do flag cells with an error icon based on data that comes in from the clipboard?
Is this even possible?

Thanks.

3 Replies

DY Deivaselvan Y Syncfusion Team September 12, 2018 03:55 AM UTC

Hi Zeljko,

Thank you for contacting Syncfusion support.

By default, error icon will be shown with tips in the cell when you try to paste the invalid data. But Validating and Validated events will not be fired for the paste operation with invalid data. These events will be fired only for the invalid data given as an input when the cell is in editing.

Still if you couldn’t see the error icon while pasting the invalid content then ensure whether you have set the GridValidationMode as either InView or InEdit. Refer the below documentation for more details on it.
https://help.syncfusion.com/wpf/sfdatagrid/data-validation#built-in-validations

If you would like to do any customization or any evaluation while pasting the content then you can achieve that requirement in the GridPasteContent event of SfDataGrid. Refer the below documentation for more details.
https://help.syncfusion.com/wpf/sfdatagrid/clipboard-operations#gridpastecontent

Please let us know if you have any other questions.

Regards,
Deivaselvan 



ZL Zeljko Lazic September 12, 2018 03:19 PM UTC

Hello Deivaselvan,

You hit upon what I was looking to do. Specifically, I need to check for duplicate string properties.

There appear to be 2 events for a paste:

         GridPasteContent
         PasteGridCellContent (it's only processing a cell at a time, too restrictive)

How do I access the entire clipboard contents from a handler to GridPasteContent?

Thanks.



DY Deivaselvan Y Syncfusion Team September 13, 2018 09:29 AM UTC

Hi Zeljiko,

You can get the clipboard contents in GridPasteContent event by using the Clipboard.GetText() method. Please refer the below code snippets. 
  
this.dataGrid.GridPasteContent += dataGrid_GridPasteContent;  
  
  
private void dataGrid_GridPasteContent(object sender, GridCopyPasteEventArgs e)  
{  
    object text = Clipboard.GetText();  
    //Splits the row into number of cells by using \t.  
    text = Regex.Split(text.ToString(), @"\t");  
    var copyValue = (string[])text;  
  
}  

Please let us know if you have any other questions.

Regards,
Deivaselvan 


Loader.
Up arrow icon