DataGridViewColumnCollection.GetColumnCount(DataGridViewElementStates) 메서드

정의

지정된 필터 요구 사항을 충족시키는 열의 수를 반환합니다.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 값의 비트 조합입니다.A bitwise combination of the DataGridViewElementStates values that represent the filter for inclusion.

반환

필터 요구 사항을 충족시키는 열의 수입니다.The number of columns that meet the filter requirements.

예외

includeFilterDataGridViewElementStates 값의 유효한 비트 조합이 아닌 경우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

적용 대상

추가 정보