DataGridView.ClipboardCopyMode Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a value that indicates whether users can copy cell text values to the Clipboard and whether row and column header text is included.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member ClipboardCopyMode : DataGridViewClipboardCopyMode with get, set

Exception Condition

The specified value when setting this property is not a valid DataGridViewClipboardCopyMode value.

The DataGridView control copies the text representation of each selected cell to the Clipboard. This value is the cell value converted to a string or, for image cells, the value of the Description property.

Values are copied to the Clipboard in Text, UnicodeText, Html, and CommaSeparatedValue formats. These formats are useful for pasting content into applications such as Notepad, Microsoft Excel, and Microsoft Word.

The DataGridView control copies the cells contained in the smallest rectangle that includes all selected cells. Rows and columns that do not contain any selected cells are not represented in the copied data. Any unselected cells in the remaining rows and columns are represented by blank placeholders. Depending on the copy mode and the selection mode, header values for the copied rows and columns may be copied, as well.

When users copy content, the DataGridView control adds a DataObject to the Clipboard. This data object is retrieved from the GetClipboardContent method. You can call this method when you want to programmatically add the data object to the Clipboard.

The GetClipboardContentmethod retrieves values for individual cells by calling the DataGridViewCell.GetClipboardContent method. You can override either or both of these methods in derived classes to customize the layout of copied cells or to support additional data formats.

For more information about Clipboard operations and data formats, see the Clipboard class.

The following code example demonstrates how to enable copying in the DataGridView control. This example is part of a larger example available in How to: Enable Users to Copy Multiple Cells to the Clipboard from the Windows Forms DataGridView Control.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top