CTRL-C on datagrid - how to remove line feed when pasting


  • It appears that the default behavior for copying (read-only) cells from a datagrid is to include a final line feed. Users then need to delete the line feed after pasting. I've tried to manipulate the clipboard contents, with no luck. How can I remove the line feed?

    private void DataGrid_OnCopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e)
    Technically, I only want the first column data, and I'm able to achieve that, but there is always a line feed.

    Thursday, March 08, 2018 3:33 PM

All replies

  • Hi,

    I don't know, how do you copy and paste.

    But you can  get Clipboard Data with remove the specific  characters as below.

     string ClipboardData=((string)Clipboard.GetData(DataFormats.Text)).TrimEnd('\r', '\n');

    Then you can set data for the Clipboard  as below,

    Clipboard.SetData(DataFormats.Text, ClipboardData);

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, March 09, 2018 2:56 AM
  • Clipboard.SetData is ignored when copying from a datagrid.

    The only object you have to work with is:


    where e is DataGridRowClipboardEventArgs



    Thursday, March 15, 2018 2:10 PM