Articles in this section
Category / Section

How to append the new text in clipboard which is not available in DataGrid(SfDataGrid)?

1 min read

By default, SfDataGrid copies the selected row or cell data in clipboard, you need to append the new text in clipboard which is not available in SfDataGrid can be achieve by overriding the CopyCells and CopyCellRow method in GridCutCopyPaste class.

 

 
dataGrid.GridCopyPaste = new CustomCopyPaste(dataGrid as SfDataGrid); 
 
public class CustomCopyPaste : GridCutCopyPaste 
{ 
 
    public CustomCopyPaste(SfDataGrid sfGrid) : base(sfGrid) 
    { 
    }    
 
    protected override void CopyCells(GridSelectedCellsCollection selectedCells, StringBuilder text) 
    { 
        base.CopyCells(selectedCells, text); 
        text.Insert(0, "\t"); 
    } 
 
    protected override void CopyCellRow(GridSelectedCellsInfo row, ref StringBuilder text) 
    { 
        base.CopyCellRow(row, ref text); 
        var DataTable = (dataGrid.ItemsSource as DataTable); 
        int index = DataTable.Rows.IndexOf((row.RowData as DataRowView).Row as System.Data.DataRow) + 1; 
        string value = "Row_" + index + "\t"; 
        text.Insert(0, value); 
    } 
}   
 

 

SfDataGrid Clipboard

 

View Sample in GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied