This documentation is archived and is not being maintained.

DataGridView.ClipboardCopyMode Property

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)

public DataGridViewClipboardCopyMode ClipboardCopyMode { get; set; }


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 GetClipboardContent method 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.

private void Form1_Load(object sender, System.EventArgs e)
    // Initialize the DataGridView control. 
    this.DataGridView1.ColumnCount = 5;
    this.DataGridView1.Rows.Add(new string[] { "A", "B", "C", "D", "E" });
    this.DataGridView1.Rows.Add(new string[] { "F", "G", "H", "I", "J" });
    this.DataGridView1.Rows.Add(new string[] { "K", "L", "M", "N", "O" });
    this.DataGridView1.Rows.Add(new string[] { "P", "Q", "R", "S", "T" });
    this.DataGridView1.Rows.Add(new string[] { "U", "V", "W", "X", "Y" });
    this.DataGridView1.ClipboardCopyMode = 

private void CopyPasteButton_Click(object sender, System.EventArgs e)
    if (this.DataGridView1
        .GetCellCount(DataGridViewElementStates.Selected) > 0)
            // Add the selection to the clipboard.

            // Replace the text box contents with the clipboard text. 
            this.TextBox1.Text = Clipboard.GetText();
        catch (System.Runtime.InteropServices.ExternalException)
            this.TextBox1.Text = 
                "The Clipboard could not be accessed. Please try again.";

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0