DataGridViewClipboardCopyMode 열거형

정의

DataGridView 컨트롤의 내용이 클립보드로 복사되는지 여부를 나타내는 상수를 정의합니다.

public enum class DataGridViewClipboardCopyMode
public enum DataGridViewClipboardCopyMode
type DataGridViewClipboardCopyMode = 
Public Enum DataGridViewClipboardCopyMode
상속
DataGridViewClipboardCopyMode

필드

Disable 0

클립보드로 복사할 수 없습니다.

EnableAlwaysIncludeHeaderText 3

선택된 셀의 텍스트 값을 클립보드로 복사할 수 있습니다. 선택한 셀이 들어 있는 행 및 열의 머리글 텍스트가 포함됩니다.

EnableWithAutoHeaderText 1

선택된 셀의 텍스트 값을 클립보드로 복사할 수 있습니다. SelectionMode 속성이 RowHeaderSelect 또는 ColumnHeaderSelect로 설정되고 하나 이상의 머리글이 선택된 경우에만 선택한 셀이 들어 있는 행 또는 열의 머리글 텍스트가 포함됩니다.

EnableWithoutHeaderText 2

선택된 셀의 텍스트 값을 클립보드로 복사할 수 있습니다. 머리글 텍스트는 포함되지 않습니다.

예제

다음 코드 예제에서 복사를 사용 하도록 설정 하는 방법에 설명 합니다 DataGridView 제어 합니다. 전체 예제를 참조 하세요 방법: Windows Forms DataGridView 컨트롤에서 클립보드로 복사 여러 셀에 대 한 사용자를 사용 하도록 설정합니다.

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.";
        }
    }
}
Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Me.Load

    ' Initialize the DataGridView control.
    Me.DataGridView1.ColumnCount = 5
    Me.DataGridView1.Rows.Add(New String() {"A", "B", "C", "D", "E"})
    Me.DataGridView1.Rows.Add(New String() {"F", "G", "H", "I", "J"})
    Me.DataGridView1.Rows.Add(New String() {"K", "L", "M", "N", "O"})
    Me.DataGridView1.Rows.Add(New String() {"P", "Q", "R", "S", "T"})
    Me.DataGridView1.Rows.Add(New String() {"U", "V", "W", "X", "Y"})
    Me.DataGridView1.AutoResizeColumns()
    Me.DataGridView1.ClipboardCopyMode = _
        DataGridViewClipboardCopyMode.EnableWithoutHeaderText

End Sub

Private Sub CopyPasteButton_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles CopyPasteButton.Click

    If Me.DataGridView1.GetCellCount( _
        DataGridViewElementStates.Selected) > 0 Then

        Try

            ' Add the selection to the clipboard.
            Clipboard.SetDataObject( _
                Me.DataGridView1.GetClipboardContent())

            ' Replace the text box contents with the clipboard text.
            Me.TextBox1.Text = Clipboard.GetText()

        Catch ex As System.Runtime.InteropServices.ExternalException
            Me.TextBox1.Text = _
                "The Clipboard could not be accessed. Please try again."
        End Try

    End If

End Sub

설명

이 열거형은에서 사용 된 ClipboardCopyMode 여부 사용자가 선택한 셀의 텍스트 값을 클립보드에 복사할 수 및 행 및 열 머리글 텍스트에 포함 되는지 여부를 나타내는 속성입니다.

적용 대상

추가 정보