wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase.md
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
public event PastingFromClipboardEventHandler PastingFromClipboard
Public Event PastingFromClipboard As PastingFromClipboardEventHandler
The PastingFromClipboard event's data class is DevExpress.Xpf.Grid.PastingFromClipboardEventArgs.
GridControl provide two events that allow you to manually process clipboard operations.
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:
<dxg:GridControl x:Name="gridControl"
PastingFromClipboard="gridControl_PastingFromClipboard"
AutoGenerateColumns="AddNew"
ItemsSource="{Binding MyObjects}"
SelectionMode="Cell">
<!--...-->
</dxg:GridControl>
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