DataGridViewColumnCollection.GetLastColumn 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回顯示順序中最後一個符合所指定篩選條件需求的資料行。
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
表示要套用於包含之篩選器的 DataGridViewElementStates 值的位元組合。
- excludeFilter
- DataGridViewElementStates
表示要套用於排除之篩選器的 DataGridViewElementStates 值的位元組合。
傳回
顯示順序中最後一個符合所指定篩選條件需求的資料行;如果找不到任何資料行,則為 null
。
例外狀況
至少有一個篩選條件值不是 DataGridViewElementStates 值的有效位元組合。
範例
下列程式碼範例會 GetLastColumn 使用 方法來交換最後一個顯示的資料行和第一個顯示的資料行。
// 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
備註
顯示順序的最後一個資料行是值最高的 DisplayIndex 資料行,不論資料行是否實際顯示在畫面上。
這個方法可讓您判斷符合指定準則的最後一個資料行,而不需要直接比較索引值。