Back to Devexpress

Copy Operations

wpf-114914-controls-and-libraries-data-grid-data-editing-and-validation-clipboard-management-copy-operations.md

latest5.7 KB
Original Source

Copy Operations

  • May 27, 2025
  • 3 minutes to read

The GridControl allows users to copy data displayed within a grid view to the Clipboard.

Copy at Runtime

Users can press Ctrl+C or Ctrl+Insert to copy data selected in the GridControl to the clipboard in formats compatible with third-party applications (Microsoft Word or Excel, for example).

The following image demonstrates a copy operation from the GridControl to Excel:

Data Copy Specifics

  • Only visible column content is copied.
  • Only grouping column values are copied for selected group rows. All hidden rows in collapsed group rows are ignored.

Copy in Code

Users can copy only selected rows or cells. However, the GridControl includes the following methods that can copy any visible rows or cells:

MethodDescription
DataControlBase.CopyRowsToClipboardCopies values displayed in specified rows/cards to the clipboard.
DataControlBase.CopyRangeToClipboardCopies values displayed within the specified row/card range to the clipboard.
DataControlBase.CopySelectedItemsToClipboardCopies values displayed in all selected rows to the clipboard.
DataControlBase.CopyCurrentItemToClipboardCopies values displayed within the focused row to the clipboard.
DataControlBase.CopyToClipboardCopies values displayed in selected rows or cells to the clipboard.
TableView.CopyCellsToClipboardCopies values displayed in specified cells to the clipboard.
TableView.CopySelectedCellsToClipboardCopies values displayed in selected cells to the clipboard.

The following example copies all visible rows to the clipboard:

xaml
<dxg:GridControl Name="grid" />  
<Button Click="OnClick">Copy to Clipboard</Button>
csharp
void OnClick(object sender, RoutedEventArgs e) {
   grid.CopyRangeToClipboard(grid.GetRowHandleByVisibleIndex(0), grid.GetRowHandleByVisibleIndex(grid.VisibleRowCount - 1));
}

Copy with Formatting

Row values are copied to the clipboard as text (the default setting):

  • Newline strings ("\r ") separate rows in the clipboard.
  • The TAB character ("\t") separates cell values within a row.

The GridControl allows users to copy data and conditional formatting (fonts, cell background, and content color) to the clipboard. When you paste copied data in Microsoft Word, Excel, or Outlook, the original formatting persists:

Set the DataViewBase.ClipboardMode property to Formatted to copy GridControl data with conditional formatting:

xaml
<dxg:GridControl>
   <dxg:GridControl.View>
      <dxg:TableView ClipboardMode="Formatted" />
   </dxg:GridControl.View>
</dxg:GridControl>

Process Copy Operations

APIDescription
DataControlBase.ClipboardCopyModeGets or sets how data is copied to the clipboard.
DataViewBase.ClipboardCopyOptionsSpecifies formats (Csv, Excel, Html, Rtf, Txt) with which the data copied from this Grid Control is compatible.
ColumnBase.CopyValueAsDisplayTextGets or sets whether to copy formatted text or values from the data source.
GridViewBase.ClipboardCopyMaxRowCountInServerModeGets or sets the maximum number of rows/cards that can be copied to the clipboard in Server Mode.
TableView.ClipboardRowCopying / TreeListView.ClipboardNodeCopyingAllow you to apply a format, change the copied data, or skip a data row or header. These events are raised before a data row, group row, column headers, or band headers are copied to the clipboard.
GridControl.CopyingToClipboardAllows you to process copy operations manually. This event is raised before row values are copied to the clipboard by a user or in code.

See Also

Breaking Change - Component functionality changes due to BinaryFormatter deprecation