Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6674321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:43:52+00:00 2026-05-26T03:43:52+00:00

With the default copy/paste behavior in the WPF DataGrid, it seems to place a

  • 0

With the default copy/paste behavior in the WPF DataGrid, it seems to place a newline after whatever is copied, whether it is the content of one cells or multiple rows.

Is there an easy way to make it not place that newline in the copied text?

I suppose I could do something like listening to Ctrl-C, executing the application.copy command, then replacing the data that was copied with a version that has the newline stripped off. That seems awfully messy, though. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:43:53+00:00Added an answer on May 26, 2026 at 3:43 am

    I ended up going with the messy-seeming solution I described above. It works, but it sure feels like there should be a better way of doing it. Maybe in the future they’ll add an event that hooks in at the right time to be able to edit the full clipboard contents directly before setting them.

        private RelayCommand _resultsGridCopyCommand;
        public RelayCommand ResultsGridCopyCommand {
            get {
                if (_resultsGridCopyCommand == null) {
                    _resultsGridCopyCommand = new RelayCommand(this.CopyFromResultsGrid);
                }
    
                return _resultsGridCopyCommand;
            }
        }
    
        private void CopyFromResultsGrid(object grid) {
            var resultsGrid = (DataGrid)grid;
            ApplicationCommands.Copy.Execute(null, resultsGrid);
    
            var oldData = Clipboard.GetDataObject();
            var newData = new DataObject();
    
            foreach (var format in oldData.GetFormats()) {
                if (format.Equals("UnicodeText") || format.Equals("Text")) {
                    newData.SetData(format, Regex.Replace(((String)oldData.GetData(format)), "\r\n$", ""));
                } else {
                    newData.SetData(format, oldData.GetData(format));
                }
            }
    
            Clipboard.SetDataObject(newData);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There doesn't seem to be a default context menu (with copy, paste, etc.) for
In my web-application (asp.net, C#) in solution explore I copy and paste the default.aspx
Is it possible to add a special action to default copy / paste menu
How to enable the default text highlights menu like: Copy/Paste/Search/Share in android webview ?
By default when you copy/paste data from a query window in SSMS it does
By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML
By default, when you try to copy from a JTable , the toString method
Is it safe to just copy/paste a specific sqlite file with .localstorage extension in
I want to suppress Cut, Copy and Paste operations in Text Box. I don't
First, I'm just starting to learn MySQL with PHP. My query copy/paste directly from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.