Aracılığıyla paylaş


DataGridView.GetCellCount(DataGridViewElementStates) Yöntem

Tanım

Sağlanan filtreyi karşılayan hücre sayısını alır.

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

Parametreler

includeFilter
DataGridViewElementStates

Sayılacak hücreleri belirten değerlerin bit düzeyinde birleşimi DataGridViewElementStates .

Döndürülenler

Parametresiyle includeFilter eşleşen hücre sayısı.

Özel durumlar

includeFilter değerini ResizableSetiçerir.

Örnekler

Aşağıdaki kod örneği, bir denetimde DataGridView seçili hücre olup olmadığını belirlemek için bu yöntemin nasıl kullanılacağını gösterir. Bu örnekte, herhangi bir hücre seçilirse, değerleri yöntemi aracılığıyla GetClipboardContent alınır ve bir TextBox denetimde görüntülenir.

Bu kod, denetimin Pano özelliklerinin DataGridView kullanımını gösteren daha büyük bir örneğin parçasıdır. Bu örnek, Nasıl yapılır: Kullanıcıların Windows Forms DataGridView Denetiminden Panoya Birden Çok Hücre Kopyalamasını Etkinleştirme bölümünde bulunan daha büyük bir örneğin parçasıdır.

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

Açıklamalar

Bu yöntem, belirli bir durumdaki hücre sayısını belirlemek için yararlıdır. Örneğin, seçili hücrelerin sayısını almak için bu yöntemi değeriyle DataGridViewElementStates.Selected kullanın. Bu genellikle özelliğini kullanmaktan daha verimlidir SelectedCells .

Şunlara uygulanır

Ayrıca bkz.