We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to copy active cell value alone when row selection in WPF DataGrid (SfDataGrid)?

Platform: WPF |
Control: SfDataGrid

All the record contents will be copied to the clipboard by default when the SelectionUnit is set as Row in WPF DataGrid (SfDataGrid). You can copy the active cell value alone by using the SfDataGrid.GridCopyCellContent event. You can remove tab character from the copied data by overriding the CopyCell method in GridCutCopyPaste class.

Refer to the following code example to copy the data of active cell alone.

this.AssociatedObject.CopyGridCellContent += AssociatedObject_CopyGridCellContent;
private void AssociatedObject_CopyGridCellContent(object sender, GridCopyPasteCellEventArgs e)
     //Skip to copy contents for all the inactive cells from the selected row 
     SfDataGrid grid = e.OriginalSender is DetailsViewDataGrid ? (SfDataGrid)e.OriginalSender : (SfDataGrid)sender;
     if (grid != null && grid.SelectionController != null
         && grid.SelectionController.CurrentCellManager != null
         && grid.SelectionController.CurrentCellManager.CurrentCell != null
         && e.Column.MappingName != grid.SelectionController.CurrentCellManager.CurrentCell.GridColumn.MappingName)
           e.Handled = true;


Refer to the following code example to remove tab character from the copied data.

this.AssociatedObject.GridCopyPaste = new CustomGridCopyPaste(this.AssociatedObject);
public class CustomGridCopyPaste : GridCutCopyPaste
    public CustomGridCopyPaste(SfDataGrid dataGrid):base(dataGrid)
    protected override void CopyCell(object record, GridColumn column, ref StringBuilder text)
         base.CopyCell(record, column, ref text);
         text.Replace("\t", string.Empty);


View sample in GitHub.

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile