Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Collapse]Common Features
  [Expand]Data Binding Common Concepts
  [Expand]Data Source Wizard
  [Expand]Expressions
  [Expand]Behaviors
  [Expand]Application Appearance
  [Expand]Filtering UI Context
  [Expand]High DPI Support
  [Expand]Scaffolding Wizard
  [Expand]Formatting Values
   HTML Text Formatting
  [Expand]Menus
  [Expand]Tooltip Management
  [Expand]Saving and Restoring Layouts
   Clipboard - Copy and Paste Operations. Data Formatting
   Version Compatibility: Default Property Values
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Clipboard - Copy and Paste Operations. Data Formatting

Expanded Copy Data

Certain DevExpress controls allow end-users to copy the control's selected data to the Clipboard using the CTRL+C shortcut. These controls also provide the CopyToClipboard method to copy a selection programmatically.

The Data Grid control also provides additional options to control data copying operations. These options are accessible from the GridView.OptionsClipboard object.

The following additional Clipboard options are accessible from the Tree List control's TreeList.OptionsClipboard object:

Expanded Copy Formatting

The Copy Formatting feature, supported by the Data Grid and Tree List controls, allows end-users to copy the control's selection along with formatting settings (fonts, cell background and foreground) to the Clipboard in RTF, HTML and Biff8 (XLS) formats. When pasting this data in MS Word, MS Excel or MS Outlook, the data retains its original formatting. This is a cross-platform functionality, supported for Data Grid and Tree List controls for WinForms and WPF platforms.

To enable the Copy Formatting feature, set the control's ClipboardMode option (ClipboardOptions.ClipboardMode) to Formatted. This option is accessible from the GridView.OptionsClipboard and TreeList.OptionsClipboard properties for WinForms Grid and TreeList controls, respectively.

In Formatted data copy mode, the selection is copied in multiple formats simultaneously: RTF, HTML, XLS (Biff8), CSV, UnicodeText, and Text. You can disable specific formats (for example, to improve application performance) using the control's OptionsClipboard object.

The following are additional settings supported in Formatted data copy mode:
Note

The WinForms Data Grid supports the Copy Formatting feature for the following Views: GridView, BandedGridView, and AdvBandedGridView.

Expanded Paste Data

Starting with version 17.2, end-users can use the CTRL+V and SHIFT+INSERT keyboard combinations to paste plain and formatted data in the Data Grid (GridView and BandedGridView) and Tree List controls in the following formats:

  • Biff8 (MS Excel)
  • Comma-separated values (CSV)
  • XML Spreadsheet
  • ANSI and Unicode text format. TAB characters separate column values; end-of-line characters separate rows.

To enable pasting, set the ClipboardOptions.PasteMode property (available from GridView.OptionsClipboard/TreeList.OptionsClipboard) to Append or Update:

  • Append - When pasting data, new rows are added to the control with clipboard values. For bound controls, the new rows are added to the data source and the control is updated. The data source should support adding new rows. Otherwise, the paste operation fails.
  • Update - The pasted data updates the rectangular cell block whose upper left corner is the currently focused cell. Cells in the columns that are displayed before the focused column are NEVER updated.

    See the following animation that shows which cells are updated when pasting two rows of text in the grid when the second visible column is focused. The TAB character separates pasted text items which can be converted to a numeric type.

    Note that cells in the first visible column are not updated during pasting.

Expanded Data Pasting Specifics

Expanded Customize Paste Operations

You can handle the following events to override the default pasting behavior and perform custom actions:

These events repeatedly fire for each pasted row and provide the following arguments to identify and modify the pasted data and cancel certain paste operations:
  • Values - Returns a dictionary that contains "target column - pasted value" pairs. You can modify pasted values in this dictionary to perform custom pasting.
  • OriginalValues - Returns a read-only collection of individual pasted values.
  • IsRowValid, IsNodeValid, and IsValueValid - Boolean methods that allow you to check data validity.
  • GetValidValues, GetInvalidValues - Return valid and invalid values.
  • PasteMode - Gets or sets whether only valid rows or all rows are pasted to the control.
  • Cancel - Gets or sets whether the current operation needs to be canceled.

In the following sample, "Yes" and "No" string values are pasted to a Boolean Grid column. This causes the e.IsRowValid method to return false and the e.GetInvalidRow method to return invalid values. The e.Values collection allows you to replace these strings with true and false values.

You can also handle this event to modify pasted values when they are valid. The sample below removes underscore characters from pasted strings and applies the "camel case" formatting to them.

Related API

Expanded Demos

How would you rate this topic?​​​​​​​