Articles in this section
Category / Section

How to copy one cell and paste it into all the selected cells in the SfDataGrid like the Excel in WPF ?

2 mins read

In the SfDataGrid, you can copy one cell and paste it into another cell, by default. To copy one cell and paste it into the selected cell, override the GridCutPaste. GridCutPaste class that has many overrides to customize copy and paste operations. To achieve the above requirement, you can override the PasteToCells(object clipboardrows) as given in the following code example.

C#

this.sfdatagrid.GridCopyPaste = new CustomCopyPaste(sfdatagrid);
…….
public class CustomCopyPaste : GridCutCopyPaste
{
    public CustomCopyPaste(SfDataGrid sfgrid)
        : base(sfgrid)
    {
    }
    protected override void PasteToCells(object clipboardrows)
    {
        var data = (IList)clipboardrows;
        var firstrowdata = Regex.Split(data[0].ToString(), @"\t");
        //Gets the ClipboardText and checks when the clipboard text is more than one cell
        // calls the base.
        if (data.Count > 1 || firstrowdata.Count() > 1)
        {
            base.PasteToCells(clipboardrows);
            return;
        }
        //Gets the selected cells to paste the copied cell 
        var selectedcells = this.dataGrid.GetSelectedCells();
        int selectedcellscount = selectedcells.Count;
        for (int i = 0; i < selectedcellscount; i++)
        {
            var record = selectedcells[i].RowData;
            var column = selectedcells[i].Column;
            //Calls PasteToCell method with particular record of selectedcells,
            // Column of selected records and rowdata
            PasteToCell(record, column, data[0]);
        }
    }
}

 

Sample Links:

 

WPF

 

WinRT

 

UWP


Conclusion

I hope you enjoyed learning about how to copy one cell and paste it into all the selected cells in the SfDataGrid like the Excel in WPF.

You can refer to our WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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