英語で読む

次の方法で共有


DataGridViewClipboardCopyMode 列挙型

定義

DataGridView コントロールからクリップボードに内容をコピーするかどうかを示す定数を定義します。

C#
public enum DataGridViewClipboardCopyMode
継承
DataGridViewClipboardCopyMode

フィールド

名前 説明
Disable 0

クリップボードへのコピーは無効です。

EnableAlwaysIncludeHeaderText 3

選択されたセルのテキスト値をクリップボードにコピーできます。 選択されたセルを含む行および列のヘッダー テキストも含まれます。

EnableWithAutoHeaderText 1

選択されたセルのテキスト値をクリップボードにコピーできます。 選択されたセルを含む行または列の行ヘッダーまたは列ヘッダー テキストは、SelectionMode プロパティが RowHeaderSelect または ColumnHeaderSelect に設定されており、1 つ以上のヘッダーが選択されている場合にのみ含まれます。

EnableWithoutHeaderText 2

選択されたセルのテキスト値をクリップボードにコピーできます。 ヘッダー テキストは含まれません。

次のコード例は、 コントロールでコピーを有効にする方法を DataGridView 示しています。 完全な例については、「方法: ユーザーが Windows フォーム DataGridView コントロールから複数のセルをクリップボードにコピーできるようにする」を参照してください。

C#
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.AutoResizeColumns();
    this.DataGridView1.ClipboardCopyMode = 
        DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
}

private void CopyPasteButton_Click(object sender, System.EventArgs e)
{
    if (this.DataGridView1
        .GetCellCount(DataGridViewElementStates.Selected) > 0)
    {
        try
        {
            // Add the selection to the clipboard.
            Clipboard.SetDataObject(
                this.DataGridView1.GetClipboardContent());
            
            // 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.";
        }
    }
}

注釈

この列挙は、 プロパティによって使用され ClipboardCopyMode 、ユーザーが選択したセルのテキスト値をクリップボードにコピーできるかどうか、および行と列のヘッダー テキストが含まれるかどうかを示します。

適用対象

製品 バージョン
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

こちらもご覧ください