DataGridView.GetCellCount(DataGridViewElementStates) 메서드

정의

제공된 필터를 충족하는 셀의 수를 가져옵니다.

public:
 int GetCellCount(System::Windows::Forms::DataGridViewElementStates includeFilter);
public int GetCellCount (System.Windows.Forms.DataGridViewElementStates includeFilter);
member this.GetCellCount : System.Windows.Forms.DataGridViewElementStates -> int
Public Function GetCellCount (includeFilter As DataGridViewElementStates) As Integer

매개 변수

includeFilter
DataGridViewElementStates

수를 계산할 셀을 지정하는 DataGridViewElementStates 값의 비트 조합입니다.

반환

Int32

includeFilter 매개 변수와 일치하는 셀의 수입니다.

예외

includeFilter가 값 ResizableSet을 포함하는 경우

예제

다음 코드 예제에서는 컨트롤에서 선택 된 셀이 있는지 여부를 확인 하려면이 메서드를 DataGridView 사용 하는 방법을 보여 줍니다. 이 예제에서 셀을 선택하면 해당 값이 메서드를 GetClipboardContent 통해 검색되고 컨트롤에 TextBox 표시됩니다.

이 코드는 컨트롤의 클립보드 기능 사용을 보여 주는 더 큰 예제의 DataGridView 일부입니다. 이 예제는 방법에서 사용할 수 있는 더 큰 예제의 일부입니다. 사용자가 Windows Forms DataGridView 컨트롤에서 클립보드로 여러 셀을 복사할 수 있도록 합니다.

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 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

설명

이 메서드는 특정 상태의 셀 수를 확인하는 데 유용합니다. 예를 들어 선택한 셀 수를 검색하려면 이 메서드를 값과 함께 DataGridViewElementStates.Selected 사용합니다. 이는 일반적으로 속성을 사용하는 SelectedCells 것보다 더 효율적입니다.

적용 대상

추가 정보