Back to Devexpress

DataControlBase.PastingFromClipboard Event

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase.md

latest3.7 KB
Original Source

DataControlBase.PastingFromClipboard Event

Occurs when some information is pasted from the clipboard to the grid.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event PastingFromClipboardEventHandler PastingFromClipboard
vb
Public Event PastingFromClipboard As PastingFromClipboardEventHandler

Event Data

The PastingFromClipboard event's data class is DevExpress.Xpf.Grid.PastingFromClipboardEventArgs.

Remarks

GridControl provide two events that allow you to manually process clipboard operations.

  • The GridControl.CopyingToClipboard event is fired before row/cell values are copied to the clipboard by an end-user, or in code. To cancel default processing, set the event parameter’s Handled property to true. This event isn’t fired if the DataControlBase.ClipboardCopyMode property is set to None.
  • The PastingFromClipboard event is fired after an end-user has pressed Ctrl+V or Shift+Ins.

To learn more, see Clipboard Management.

Note

The GridControl.CopyingToClipboard event raises only if the GridControl has no active cell editor. The PastingFromClipboard raises no matter whether the GridControl contains an active editor.

To detect whether the GridControl contains an active cell editor at runtime, use the DataViewBase.ActiveEditor property.

The following example processes clipboard data so a user can copy and paste a rectangular area from a source table to a grid:

xaml
<dxg:GridControl x:Name="gridControl" 
                 PastingFromClipboard="gridControl_PastingFromClipboard" 
                 AutoGenerateColumns="AddNew" 
                 ItemsSource="{Binding MyObjects}" 
                 SelectionMode="Cell">
    <!--...-->
</dxg:GridControl>
csharp
private void gridControl_PastingFromClipboard(object sender, DevExpress.Xpf.Grid.PastingFromClipboardEventArgs e) {
    int baseRowIndex = tableView.FocusedRowHandle;
    int baseColumnIndex = tableView.VisibleColumns.IndexOf(gridControl.CurrentColumn as GridColumn);
    string[] clipRows = Clipboard.GetText().Split('\n');
    int i = 0;
    foreach (var clipRow in clipRows) {
        string[] clipRowCells = clipRow.Split('\t');
        int j = 0;
        foreach (var clipRowCell in clipRowCells) {
            gridControl.SetCellValue(baseRowIndex + i, tableView.VisibleColumns[baseColumnIndex + j], clipRowCell.Replace("\r", ""));
            j++;
            if (baseColumnIndex + j > tableView.VisibleColumns.Count) break;
        }
        i++;
    }
    e.Handled = true;
}

See Also

CopyingToClipboard

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace