RadGridView cell copy\paste remove newline

3 posts, 0 answers
  1. Heath
    Heath avatar
    2 posts
    Member since:
    Feb 2014

    Posted 18 Nov 2014 Link to this post

    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
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 19 Nov 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Heath
    Heath avatar
    2 posts
    Member since:
    Feb 2014

    Posted 19 Nov 2014 in reply to Boris Link to this post

    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
Back to Top