WPF RadGrid ClipboardCopyMode Row and Cell

2 posts, 0 answers
  1. Pradeep
    Pradeep avatar
    8 posts
    Member since:
    Oct 2019

    Posted 18 Nov 2019 Link to this post

    WPF RadGrid ClipboardCopyMode Row and Cell 

    Can we differentiate when we copy entire row or a single cell?

     

    For Row selection we need row values with headers. Sp using these properties we can include headers too ClipboardCopyMode="All" CopyingCellClipboardContent="

     

    For cell copying can we ignore the header? 

     

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1136 posts

    Posted 21 Nov 2019 Link to this post

    Hello Pradeep,

    One idea that comes to my mind is to handle the CopyingCellClipboardContent, Copying and Copied events in the following manner:

            private bool copyingWholeRow;
    
            private void clubsGrid_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
            {
                if (!copyingWholeRow && e.CellType == GridViewCellType.HeaderCell)
                {
                    e.Cancel = true;
                }
            }
    
            private void clubsGrid_Copying(object sender, GridViewClipboardEventArgs e)
            {
                var columnCount = this.clubsGrid.Columns.OfType<GridViewColumn>().Where(c => c.IsVisible).Count();
                if (this.clubsGrid.SelectedCells.Count % columnCount == 0)
                {
                    copyingWholeRow = true;
                    this.clubsGrid.ClipboardCopyMode = GridViewClipboardCopyMode.All;
                }
                else
                {
                    this.clubsGrid.ClipboardCopyMode = GridViewClipboardCopyMode.Cells;
                }
            }
    
            private void clubsGrid_Copied(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                copyingWholeRow = false;
            }

    I've prepared a small sample project to demonstrate this approach.

    Please give this a try and let me know if a similar approach works at your end.

    Regards,
    Dilyan Traykov
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top