Copying
This article will give you a basic understanding on how to use:
ClipboardCopyMode
Copying to the Clipboard is controlled by the ClipboardCopyMode property on RadGridView. It is a Flags Enumeration of type GridViewClipboardCopyMode.
Here's a list of all the available values:
- None: Copying is disabled.
- Cells: Copy grid cells.
- Header: Copy grid header.
- Footer: Copy grid footer.
- SkipEmptyRows: Will not copy rows with values that are all null or empty. (introduced with Q1 2016)
- SkipEmptyColumns: Will not copy columns with values that are null or empty. (introduced as of R3 2017 SP1)
- All: Copy cells, header and footer.
The default value is Cells.
Here is an example on how to copy column headers as well as selected data:
Example 1: Setting the ClipboardCopyMode in code
this.radGridView.ClipboardCopyMode = GridViewClipboardCopyMode.Cells |
GridViewClipboardCopyMode.Header;
Me.radGridView.ClipboardCopyMode = GridViewClipboardCopyMode.Cells Or GridViewClipboardCopyMode.Header
Example 2: Setting the ClipboardCopyMode in xaml
<telerik:RadGridView ClipboardCopyMode="Cells, Header" />
Events
With the initial implementation, the CopyingCellClipboardContent will be thrown for the cells only. As of the 2017.3.1023 latest internal build and with the R1 2018 official version, the event will be thrown for the header and footer cells as well.
There are two events that allow you to control the copying operation: Copying and CopyingCellClipboardContent. The first allows you to cancel a copying operation, whereas the second event allows you to cancel copying for a single cell or override the value to be copied to the Clipboard. The latter is especially useful if you have columns with custom cell templates and you would like to be able to place their values in the clipboard. Here is an example of how you can accomplish that:
Example 3: The CopyingCellClipboardContent Event
private void radGridView_CopyingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e)
{
if (e.Cell.Column.UniqueName == "FullName")
{
var person = e.Cell.Item as Person;
e.Value = string.Format("{0} {1} {2}", person.FirstName, person.MiddleName, person.LastName);
}
}
Private Sub radGridView_CopyingCellClipboardContent(sender As Object, e As GridViewCellClipboardEventArgs)
If e.Cell.Column.UniqueName = "FullName" Then
Dim person = TryCast(e.Cell.Item, Person)
e.Value = String.Format("{0} {1} {2}", person.FirstName, person.MiddleName, person.LastName)
End If
End Sub
For some interesting examples, like how to skip copying of GridViewSelectColumn and GridViewToggleRowDetailsColumn, please check our SDK example browser.