Edit this page

Copying

This article will give you a basic understanding on how to use:

CliboardCopyMode

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)
  • 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:

[C#] Example 1: Setting the ClipboardCopyMode

this.radGridView.ClipboardCopyMode = GridViewClipboardCopyMode.Cells |
GridViewClipboardCopyMode.Header;

[VB.NET] Example 1: Setting the ClipboardCopyMode

Me.radGridView.ClipboardCopyMode = GridViewClipboardCopyMode.Cells Or GridViewClipboardCopyMode.Header

Events

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:

[C#] Example 2: 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);
    }
}

[VB.NET] Example 2: The CopyingCellClipboardContent Event

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.

See also