New to Telerik UI for WPF? Download free 30-day trial

Pasting

Pasting is controlled similarly to Copying. The ClipboardPasteMode property on RadGridView, also a flags enumeration of type GridViewClipboardPasteMode, dictates how pasting is performed. The values None, Cells, SkipFirstLine and SkipLastLine are counterparts of GridViewClipboardCopyMode’s None, Cells, Header and Footer, respectively. There are few more values which are of interest:

  • OverwriteWithEmptyValues – If the data you are pasting from the Clipboard contains empty cells, the respective cells in the receiving RadGridView will be cleared.

  • SkipHiddenColumns - if a column is hidden, you will still paste in its underlying property unless this flag is on. Added in Q2 2010 SP1.

  • AllSelectedCells - if pasting only one cell's value from the Clipboard, RadGridView will try to paste it to each selected cell.

  • AllSelectedRows - if pasting one or more items from the Clipboard, RadGridView will try to paste it to each selected row.

  • InsertNewRows - if pasting one or more items from the Clipboard, RadGridView will try to create new row for them.

The default mode is pasting into Cells.

You need to have a selected element (row or cell) set in RadGridView in order to paste a value.

The Pasting event allows you to cancel a paste operation, whereas the PastingCellClipboardContent allows you to cancel pasting for the cell or replace the Clipboard value with your own. Example 1 shows how these events can be utilized.

Example 1: Utilizing Pasting and PastingCellClipboardContent events

private void radGridView1_Pasting(object sender, GridViewClipboardEventArgs e) 
{ 
    e.Cancel = true; 
} 
 
private void radGridView1_PastingCellClipboardContent(object sender, GridViewCellClipboardEventArgs e) 
{ 
    if (e.Cell.Column.UniqueName == "Company") 
    { 
        var companyName = e.Value.ToString(); 
        var company = this.EFContext.Companies.Where(c => c.Name == companyName).FirstOrDefault(); 
        if (company != null) 
        { 
            e.Value = company; 
        } 
        else 
        { 
            e.Cancel = true; 
        } 
    } 
} 
Private Sub radGridView1_Pasting(sender As Object, e As GridViewClipboardEventArgs) 
    e.Cancel = True 
End Sub 
 
Private Sub radGridView1_PastingCellClipboardContent(sender As Object, e As GridViewCellClipboardEventArgs) 
    If e.Cell.Column.UniqueName = "Company" Then 
        Dim companyName = e.Value.ToString() 
        Dim company = Me.EFContext.Companies.Where(Function(c) c.Name = companyName).FirstOrDefault() 
        If company IsNot Nothing Then 
            e.Value = company 
        Else 
            e.Cancel = True 
        End If 
    End If 
End Sub 

As of version R2 2013:

  • The user can copy one cell and paste its value to all the selected cells for a column. You should set the AllSelectedCells ClipboardPasteMode together with SelectionUnit=“Cell” for the RadGridView.

  • The user can copy a row and paste it to multiple selected rows. You should set the AllSelectedRows ClipboardPasteMode together with SelectionUnit=“Row” for the RadGridView.

  • The user can copy more items than the selected rows. When pasting them in the GridView, then new items will be created and the values will be pasted to them. You should set the InsertNewRows ClipboardPasteMode.

For an example please check the GridView/CopyPasteFunctionalities example here.

In this article