DataGridView.FirstDisplayedCell 屬性

定義

取得或設定目前顯示在 DataGridView 中的第一個儲存格;這個儲存格通常位於左上角。

public:
 property System::Windows::Forms::DataGridViewCell ^ FirstDisplayedCell { System::Windows::Forms::DataGridViewCell ^ get(); void set(System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell FirstDisplayedCell { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell? FirstDisplayedCell { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.FirstDisplayedCell : System.Windows.Forms.DataGridViewCell with get, set
Public Property FirstDisplayedCell As DataGridViewCell

屬性值

目前顯示在控制項中的第一個 DataGridViewCell

屬性

例外狀況

設定這個屬性時,指定的儲存格不在 DataGridView 中。

設定這個屬性時,指定儲存格的 RowIndexColumnIndex 屬性值為 -1,表示它是標題儲存格或共用的儲存格。

-或-

設定這個屬性時,指定儲存格的 Visible 屬性值為 false

範例

下列程式碼範例說明如何確保排序之後可以看到目前的儲存格。 此程式碼只適用于未系結 DataGridView 的控制項。 DataGridView當控制項系結至外部資料源時,目前儲存格不會在排序時自動儲存。

若要執行此範例,請將下列程式碼貼到包含 DataGridView 具名 dataGridView1 的表單中。 在 C# 中,您也必須將 Sorted 事件連接到事件處理常式。

private void dataGridView1_Sorted(object sender, EventArgs e)
{
    this.dataGridView1.FirstDisplayedCell = this.dataGridView1.CurrentCell;
}
Private Sub dataGridView1_Sorted(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles dataGridView1.Sorted

    Me.dataGridView1.FirstDisplayedCell = Me.dataGridView1.CurrentCell

End Sub

備註

您可以使用這個屬性來判斷控制項中目前顯示的第一列和資料行中的儲存格。 一般而言,這是在左上角,但針對從右至左的語言,其位於右上角。 您也可以將此屬性設定為將控制項捲動至指定的儲存格。

適用於

另請參閱