DataGridView.GetCellCount メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim includeFilter As DataGridViewElementStates Dim returnValue As Integer returnValue = instance.GetCellCount(includeFilter)
戻り値
includeFilter パラメータと一致するセルの数。


このメソッドは、特定の状態のセルの数を確認する場合に便利です。たとえば、選択されたセルの数を取得するには、このメソッドと DataGridViewElementStates.Selected 値を使用します。これは通常、SelectedCells プロパティを使用するよりも効率的です。

このメソッドを使用して、DataGridView コントロールで選択されたセルがあるかどうかを確認するコード例を次に示します。この例では、セルが選択されている場合、GetClipboardContent メソッドによってセルの値が取得され、TextBox コントロールに表示されます。
このコードは、DataGridView コントロールのクリップボード機能の使用について説明している例の一部です。次の例は「方法 : ユーザーが、Windows フォーム DataGridView コントロールからクリップボードに複数のセルをコピーできるようにする」で取り上げている例の一部です。
Private Sub PasteButton_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles PasteButton.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
private void PasteButton_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."; } } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
その他の技術情報
DataGridView コントロール (Windows フォーム)
- DataGridView.GetCellCount メソッドのページへのリンク