Skip to main content

Clipboard

  • 6 minutes to read

The clipboard is a set of operations that allow users to transfer data between applications.

Overview

The Data Grid and Tree List controls allow users to copy/paste rows to/from the clipboard. To copy rows to the clipboard, select the rows and press Ctrl+C. To paste data, focus the target row and press Ctrl+V or Shift+Insert.

image

Tip

Run the following demos and copy the selected rows to the clipboard:

Run Demo: Data Grid Run Demo: TreeList

Click Open Solution in the Ribbon UI to get the source code.

Note

The Vertical Grid and PDF Viewer controls support clipboard operations in plain-text mode only — format settings (fonts, colors, etc.) are not copied/pasted.

Copy

In code, use the following methods to copy the selected rows to the clipboard:

Options

Grid Control

The GridView.OptionsClipboard property provides access to the following options:

  • AllowCopy — set this property to False to prohibit users from copying data to the clipboard.
  • CopyColumnHeaders — set this property to True to include column and band headers in copied data.
  • ClipboardMode — specifies whether the control copies data to the clipboard with format settings (fonts, cell background and foreground colors) or as plain text. See Formatting below.
  • CopyCollapsedData — data rows can be grouped and collapsed. In formatted mode, this property sets whether collapsed data is copied to the clipboard. Collapsed data is never copied in plain-text mode.

Tree List

The TreeList.OptionsClipboard property provides access to the following options:

  • AllowCopy — set this property to False to prohibit users from copying data to the clipboard.
  • CopyColumnHeaders — set this property to True to include column and band headers in copied data.
  • CopyNodeHierarchy — the control copies data to the clipboard with indents that reflect the tree structure. Set this property to False to copy data without indents.
  • ClipboardMode — specifies whether the control copies data to the clipboard along with format settings (fonts, cell background and foreground colors) or as plain text. See Formatting below.
  • CopyCollapsedData — nodes can be collapsed. In formatted mode, this property sets whether collapsed data is copied to the clipboard. In plain-text mode, collapsed data is never copied.

Formatting

The Data Grid and Tree List controls support the RTF, HTML, and BIFF8 (Microsoft Excel) formats. These formats allow you to copy data along with format settings — fonts and cell colors. When data is pasted to Microsoft Word, Excel, or Outlook, the formatting is preserved.

Clipboard Manager

To copy formatted data, set the ClipboardMode property to Formatted.

gridView1.OptionsClipboard.ClipboardMode = DevExpress.Export.ClipboardMode.Formatted;
treeList1.OptionsClipboard.ClipboardMode = DevExpress.Export.ClipboardMode.Formatted;

Note

In the GridControl, only the GridView, BandedGridView, and AdvBandedGridView support copying formatted data to the clipboard.

The controls always use all supported formats. To improve performance, you can use the following options to disable the corresponding format:

Progress

The controls show a progress bar when copying or pasting large portions of formatted data.

image

Use the ShowProgress property to specify whether the progress bar is shown. Note that this property is only in effect in formatted mode.

Get Access to Data Being Copied

You can access copied data and apply a format to a cell, change the copied data, or skip a data row or header. The image below illustrates a default copy-and-paste operation.

image

The following figure illustrates the same operation with a custom format applied to the Sales column header:

image

The following events fire before a data row, group row, column headers, or band headers are copied to the clipboard, and allows you to update data or skip the row:

Data Providers

The following properties return objects that provide data for the clipboard:

These objects provide data for the clipboard in different formats (plain text, rich text, plain Unicode text, CSV, BIFF8, HTML). Use the provider’s methods to get the data selected in the control that will be passed to the clipboard if a user presses Ctrl+C. For example, the TreeListClipboardDataProvider.GetTextData method returns data for the clipboard in plain-text format.

Paste

Data pasting is initially disabled in Data Grid and Tree List controls. Use the PasteMode setting to allow paste operations.

Note

The following controls and components do not support paste operations:

Users can paste plain-text and formatted data to the Data Grid and Tree List controls. To paste data, press Ctrl+V or Shift+Insert. In code, use the following methods:

The following formats are supported:

  • BIFF8 (Microsoft Excel)
  • Comma-separated values (CSV)
  • XML Spreadsheet
  • ANSI and Unicode text format. The Tab character separates column values, and the End-of-Line character separates rows.

Paste Mode

Set the ClipboardOptions.PasteMode property to Append or Update to allow paste operations.

  • Append — the control adds new rows at the end of the list.

    If the control is bound to a data source, new rows are added to the data source (the operation fails if the data source does not allow adding new rows).

    Note

    To add new rows, the Data Grid uses the AddNewRow method. The Tree List uses the AppendNode method. See these topics for more information and limitations.

  • Update — the control updates cells below and to the right of the focused cell. Cells above and to the left of the focused column are not updated.

    The example below illustrates how data rows are updated. The clipboard contains the following tab-separated values:

    Paste-BlockSelection-TabbedNumbers

    In the animation below, a cell in the second column is focused. The control updates cells below and to the right of the focused cell. Note that the first column is not updated.

    Paste-BlockSelection.gif

    Note

Tree List Hierarchy

The PasteAsChildNodes option specifies whether to paste data as child or sibling nodes.

Get Access to Data Being Pasted

The following events fire before a data row is pasted to the control, and allows you to update data or skip the row:

Limitations

Paste operations have the following limitations:

  • If the data source does not allow adding new rows, users cannot paste data.
  • If the control is read-only or non-editable, users cannot paste data. See the ReadOnly, Editable, and AllowAddRows properties in the Data Grid. See the ReadOnly and Editable properties in the Tree List.
  • Read-only and non-editable columns are skipped. See the AllowEdit and ReadOnly properties in the Data Grid, and the AllowEdit and ReadOnly property in the Tree List.
  • If any column cannot accept the value being pasted, the row is skipped.
  • Images cannot be pasted.