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

WPF RadGrid ClipboardCopyMode Row and Cell

1 Answer 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pradeep
Top achievements
Rank 1
Pradeep asked on 18 Nov 2019, 03:48 PM

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? 

 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 21 Nov 2019, 09:54 AM

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.
Tags
General Discussions
Asked by
Pradeep
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or