Articles in this section
Category / Section

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

4 mins read

In SfDataGrid, by default you can copy one row and paste it into another row. When you need to copy one row and paste it into the selected rows, you can override GridCutCopyPaste. GridCutCopyPaste class consists of many overrides to customize copy paste operations. To achieve the above requirement, you can override PasteToRows (object clipboardrows) as 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 PasteToRows(object clipboardrows)
    {
        var data = (IList)clipboardrows;
        //Gets the ClipbordText and check if the clipboard text is more than one row
        //means call the base.
        if (data.Count > 1)
        {
            base.PasteToRows(clipboardrows);
            return;
        }
        //Gets the Selected records for paste the copied row.
        var selectedrecord = this.dataGrid.SelectedItems;
        for (int i = 0; i < selectedrecord.Count; i++)
        {
            var selectedRecords = selectedrecord[i];
            // Calls the PasteToRow method with copiedrecord and selectedrecord
            PasteToRow(data[0], selectedRecords);
        }
    }
}

Sample Links:

 

WPF

WRT

UWP

 

Conclusion

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

You can refer to our WPF SfDataGrid 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 SfDataGrid 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
Please sign in to leave a comment
Access denied
Access denied