DataGridViewColumnCollection.GetLastColumn Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the last column in display order that meets the given filter requirements.
public:
System::Windows::Forms::DataGridViewColumn ^ GetLastColumn(System::Windows::Forms::DataGridViewElementStates includeFilter, System::Windows::Forms::DataGridViewElementStates excludeFilter);
public System.Windows.Forms.DataGridViewColumn GetLastColumn (System.Windows.Forms.DataGridViewElementStates includeFilter, System.Windows.Forms.DataGridViewElementStates excludeFilter);
public System.Windows.Forms.DataGridViewColumn? GetLastColumn (System.Windows.Forms.DataGridViewElementStates includeFilter, System.Windows.Forms.DataGridViewElementStates excludeFilter);
member this.GetLastColumn : System.Windows.Forms.DataGridViewElementStates * System.Windows.Forms.DataGridViewElementStates -> System.Windows.Forms.DataGridViewColumn
Public Function GetLastColumn (includeFilter As DataGridViewElementStates, excludeFilter As DataGridViewElementStates) As DataGridViewColumn
- 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.
The last displayed column in display order that meets the given filter requirements, or null
if no column is found.
At least one of the filter values is not a valid bitwise combination of DataGridViewElementStates values.
The following code example uses the GetLastColumn method to swap the last displayed column and the first 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
The last column in display order is the column with the highest DisplayIndex value, regardless of whether the column is actually visible on the screen.
This method lets you determine the last column that fits the given criteria without having to compare index values directly.
Produit | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Commentaires sur .NET
.NET est un projet open source. Sélectionnez un lien pour fournir des commentaires :