DataGridView.GetCellCount メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridView.GetCellCount メソッドの意味・解説 

DataGridView.GetCellCount メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されフィルタ満たすセルの数を取得します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Function GetCellCount ( _
    includeFilter As DataGridViewElementStates _
) As Integer
Dim instance As DataGridView
Dim includeFilter As DataGridViewElementStates
Dim returnValue As Integer

returnValue = instance.GetCellCount(includeFilter)
public int GetCellCount (
    DataGridViewElementStates includeFilter
)
public:
int GetCellCount (
    DataGridViewElementStates includeFilter
)
public int GetCellCount (
    DataGridViewElementStates includeFilter
)
public function GetCellCount (
    includeFilter : DataGridViewElementStates
) : int

パラメータ

includeFilter

数に含めセル指定する DataGridViewElementStates 値のビットごとの組み合わせ

戻り値
includeFilter パラメータ一致するセルの数。

例外例外
例外種類条件

ArgumentException

includeFilter が値 ResizableSet を格納してます。

解説解説

このメソッドは、特定の状態のセルの数を確認する場合に便利です。たとえば、選択されセルの数を取得するには、このメソッドと 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.";
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

DataGridView.GetCellCount メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridView.GetCellCount メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS