Expand Minimize

DataGridViewClipboardCopyMode Enumeration

Defines constants that indicate whether content is copied from a DataGridView control to the Clipboard.

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

public enum DataGridViewClipboardCopyMode

Member nameDescription
DisableCopying to the Clipboard is disabled.
EnableAlwaysIncludeHeaderTextThe text values of selected cells can be copied to the Clipboard. Header text is included for rows and columns that contain selected cells.
EnableWithAutoHeaderTextThe text values of selected cells can be copied to the Clipboard. Row or column header text is included for rows or columns that contain selected cells only when the DataGridView.SelectionMode property is set to RowHeaderSelect or ColumnHeaderSelect and at least one header is selected.
EnableWithoutHeaderTextThe text values of selected cells can be copied to the Clipboard. Header text is not included.

This enumeration is used by the ClipboardCopyMode property to indicate whether users can copy the text values of selected cells to the Clipboard and whether row and column header text is included.

The following code example demonstrates how to enable copying in the DataGridView control. For the complete example, see 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.";

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft