DataGridViewColumnCollection.GetColumnCount(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnCount(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnCount(DataGridViewElementStates) DataGridViewColumnCollection.GetColumnCount(DataGridViewElementStates) Method

定義

指定したフィルター条件に一致する列の数を返します。Returns the number of columns that meet the given filter requirements.

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

パラメーター

includeFilter
DataGridViewElementStates DataGridViewElementStates DataGridViewElementStates DataGridViewElementStates

包含フィルターを表す DataGridViewElementStates 値のビットごとの組み合わせ。A bitwise combination of the DataGridViewElementStates values that represent the filter for inclusion.

戻り値

フィルター条件に一致する列の数。The number of columns that meet the filter requirements.

例外

includeFilter は、DataGridViewElementStates 値のビットごとの正しい組み合わせではありません。includeFilter is not a valid bitwise combination of DataGridViewElementStates values.

次のコード例は、このメソッドを使用して、選択した列の数を取得する方法を示しています。The following code example illustrates how to use this method to get the number of selected columns.

private void selectedColumnsButton_Click(object sender, System.EventArgs e)
{
    Int32 selectedColumnCount = dataGridView1.Columns
        .GetColumnCount(DataGridViewElementStates.Selected);
    if (selectedColumnCount > 0)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        for (int i = 0; i < selectedColumnCount; i++)
        {
            sb.Append("Column: ");
            sb.Append(dataGridView1.SelectedColumns[i].Index
                .ToString());
            sb.Append(Environment.NewLine);
        }

        sb.Append("Total: " + selectedColumnCount.ToString());
        MessageBox.Show(sb.ToString(), "Selected Columns");
    }
}
Private Sub selectedColumnsButton_Click( _
    ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles selectedColumnsButton.Click

    Dim selectedColumnCount As Integer = dataGridView1.Columns _
        .GetColumnCount(DataGridViewElementStates.Selected)

    If selectedColumnCount > 0 Then

        Dim sb As New System.Text.StringBuilder()

        Dim i As Integer
        For i = 0 To selectedColumnCount - 1

            sb.Append("Column: ")
            sb.Append(dataGridView1.SelectedColumns(i).Index.ToString())
            sb.Append(Environment.NewLine)

        Next i

        sb.Append("Total: " + selectedColumnCount.ToString())
        MessageBox.Show(sb.ToString(), "Selected Columns")

    End If

End Sub

適用対象

こちらもご覧ください