編集

次の方法で共有


DataGridViewColumnCollection.GetFirstColumn Method

Definition

Returns the first column in display order that meets the given filter requirements.

Overloads

GetFirstColumn(DataGridViewElementStates)

Returns the first column in display order that meets the given inclusion-filter requirements.

GetFirstColumn(DataGridViewElementStates, DataGridViewElementStates)

Returns the first column in display order that meets the given inclusion-filter and exclusion-filter requirements.

GetFirstColumn(DataGridViewElementStates)

Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs

Returns the first column in display order that meets the given inclusion-filter requirements.

public:
 System::Windows::Forms::DataGridViewColumn ^ GetFirstColumn(System::Windows::Forms::DataGridViewElementStates includeFilter);
public System.Windows.Forms.DataGridViewColumn GetFirstColumn (System.Windows.Forms.DataGridViewElementStates includeFilter);
public System.Windows.Forms.DataGridViewColumn? GetFirstColumn (System.Windows.Forms.DataGridViewElementStates includeFilter);
member this.GetFirstColumn : System.Windows.Forms.DataGridViewElementStates -> System.Windows.Forms.DataGridViewColumn
Public Function GetFirstColumn (includeFilter As DataGridViewElementStates) As DataGridViewColumn

Parameters

includeFilter
DataGridViewElementStates

A bitwise combination of the DataGridViewElementStates values that represents the filter for inclusion.

Returns

The first column in display order that meets the given filter requirements, or null if no column is found.

Exceptions

includeFilter is not a valid bitwise combination of DataGridViewElementStates values.

Examples

The following code example uses the GetFirstColumn method to swap the first displayed column and the last displayed column.

// Swap the last column with the first.
void Button10_Click( Object^ /*sender*/, EventArgs^ /*args*/ )
{
   DataGridViewColumnCollection^ columnCollection = dataGridView->Columns;
   DataGridViewColumn^ firstDisplayedColumn = columnCollection->GetFirstColumn( DataGridViewElementStates::Visible );
   DataGridViewColumn^ lastDisplayedColumn = columnCollection->GetLastColumn( DataGridViewElementStates::Visible, DataGridViewElementStates::None );
   int firstColumn_sIndex = firstDisplayedColumn->DisplayIndex;
   firstDisplayedColumn->DisplayIndex = lastDisplayedColumn->DisplayIndex;
   lastDisplayedColumn->DisplayIndex = firstColumn_sIndex;
}
// Swap the last column with the first.
private void Button10_Click(object sender, EventArgs args)
{
    DataGridViewColumnCollection columnCollection = dataGridView.Columns;

    DataGridViewColumn firstVisibleColumn =
        columnCollection.GetFirstColumn(DataGridViewElementStates.Visible);
    DataGridViewColumn lastVisibleColumn =
        columnCollection.GetLastColumn(
            DataGridViewElementStates.Visible, DataGridViewElementStates.None);

    int firstColumn_sIndex = firstVisibleColumn.DisplayIndex;
    firstVisibleColumn.DisplayIndex = lastVisibleColumn.DisplayIndex;
    lastVisibleColumn.DisplayIndex = firstColumn_sIndex;
}
' Swap the last column with the first.
Private Sub Button10_Click(ByVal sender As Object, _
    ByVal args As EventArgs) Handles Button10.Click

    Dim columnCollection As DataGridViewColumnCollection = _
        dataGridView.Columns

    Dim firstVisibleColumn As DataGridViewColumn = _
        columnCollection.GetFirstColumn(DataGridViewElementStates.Visible)
    Dim lastVisibleColumn As DataGridViewColumn = _
        columnCollection.GetLastColumn(DataGridViewElementStates.Visible, _
        Nothing)

    Dim firstColumn_sIndex As Integer = firstVisibleColumn.DisplayIndex
    firstVisibleColumn.DisplayIndex = _
        lastVisibleColumn.DisplayIndex
    lastVisibleColumn.DisplayIndex = firstColumn_sIndex
End Sub

Remarks

The first column in display order is the column with the lowest DisplayIndex value, regardless of whether the column is actually visible on the screen.

This method lets you determine the first column that fits the given criteria without having to compare index values directly.

See also

Applies to

GetFirstColumn(DataGridViewElementStates, DataGridViewElementStates)

Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs
Source:
DataGridViewColumnCollection.cs

Returns the first column in display order that meets the given inclusion-filter and exclusion-filter requirements.

public:
 System::Windows::Forms::DataGridViewColumn ^ GetFirstColumn(System::Windows::Forms::DataGridViewElementStates includeFilter, System::Windows::Forms::DataGridViewElementStates excludeFilter);
public System.Windows.Forms.DataGridViewColumn GetFirstColumn (System.Windows.Forms.DataGridViewElementStates includeFilter, System.Windows.Forms.DataGridViewElementStates excludeFilter);
public System.Windows.Forms.DataGridViewColumn? GetFirstColumn (System.Windows.Forms.DataGridViewElementStates includeFilter, System.Windows.Forms.DataGridViewElementStates excludeFilter);
member this.GetFirstColumn : System.Windows.Forms.DataGridViewElementStates * System.Windows.Forms.DataGridViewElementStates -> System.Windows.Forms.DataGridViewColumn
Public Function GetFirstColumn (includeFilter As DataGridViewElementStates, excludeFilter As DataGridViewElementStates) As DataGridViewColumn

Parameters

includeFilter
DataGridViewElementStates

A bitwise combination of the DataGridViewElementStates values that represent the filter to apply for inclusion.

excludeFilter
DataGridViewElementStates

A bitwise combination of the DataGridViewElementStates values that represent the filter to apply for exclusion.

Returns

The first column in display order that meets the given filter requirements, or null if no column is found.

Exceptions

At least one of the filter values is not a valid bitwise combination of DataGridViewElementStates values.

Remarks

The first column in display order is the column with the lowest DisplayIndex value, regardless of whether the column is actually visible on the screen.

This method lets you determine the first column that fits the given criteria without having to compare index values directly.

See also

Applies to