This is a migrated thread and some comments may be shown as answers.

RadGridView cell copy\paste remove newline

4 Answers 258 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Heath
Top achievements
Rank 1
Heath asked on 18 Nov 2014, 09:40 PM
Hi all,

Is there a method to simply strip the newline out after a cell copy in RadGridView. Currently I'm using CopyingCellClipboardContent to manipulate the e.Value, but when I go to paste into Notepad there's a newline added. Unfortunately, we have an webapp that doesn't like the newline character.

The work around is that I add a button column to the gridview and just use this to control the clipboard content but I'd much prefer the CTRL + C method.

Cheers

Heath

4 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 19 Nov 2014, 04:53 PM
Hello Heath,

A possible way to do this is to use the Copied event of the GridView. It occurs after the selected cells of the GridViewDataControl were copied to the Clipboard. That helps us get the already copied data in the clipboard with Clipboard.GetData() method and then replace it with the Clipboard.SetData() method. In order to display your content in one cell, you will need to remove the new line ("\n") of the initially copied clipboard data and then set it in the clipboard.

private void clubsGrid_Copied(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            string originalText = Clipboard.GetData(DataFormats.UnicodeText).ToString();
            var updatedText = originalText.Replace("\n", "");
            Clipboard.SetData(DataFormats.UnicodeText, updatedText);           
        }

I hope this helps.

Regards,
Boris
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Heath
Top achievements
Rank 1
answered on 19 Nov 2014, 07:36 PM
Thanks Boris,

I got it working like this. I feel foolish not seeing or thinking of this.

        private void dtgrd_Catelog_Copied(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            {
                string originalText = Clipboard.GetText().ToString();
                var updatedText = originalText.Replace("\n", "");
                Clipboard.SetText(updatedText);
            }
        }


Cheers
0
Dominik
Top achievements
Rank 1
answered on 29 Nov 2019, 10:54 AM
We are running into the same issue and want to get rid of the empty line at the end. But when we try to modify the clipboard in the OnCopied event we run into a COMException (0x800401D0) as it fails to open the clipboard.
0
Vladimir Stoyanov
Telerik team
answered on 04 Dec 2019, 08:27 AM

Hello Dominik,

I am afraid that I cannot say for certain what is the reason for the described behavior based on the provided information. Since, the operations involving the clipboard are not directly related to the UI for WPF controls, I can suggest searching on a general purpose forum such as stackoverflow

Of course, if you can share a runnable sample project in a new support ticket (since projects cannot be attached to forum posts), we will be glad to investigate the scenario.

Regards,
Vladimir Stoyanov
Progress Telerik

Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Heath
Top achievements
Rank 1
Answers by
Boris
Telerik team
Heath
Top achievements
Rank 1
Dominik
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or