DataGridView.FirstDisplayedCell 属性


获取或设置当前显示在 DataGridView 中的第一个单元格;此单元格通常位于左上角。Gets or sets the first cell currently displayed in the DataGridView; typically, this cell is in the upper left corner.

 property System::Windows::Forms::DataGridViewCell ^ FirstDisplayedCell { System::Windows::Forms::DataGridViewCell ^ get(); void set(System::Windows::Forms::DataGridViewCell ^ value); };
public System.Windows.Forms.DataGridViewCell FirstDisplayedCell { get; set; }
member this.FirstDisplayedCell : System.Windows.Forms.DataGridViewCell with get, set
Public Property FirstDisplayedCell As DataGridViewCell


当前显示在控件中的第一个 DataGridViewCellThe first DataGridViewCell currently displayed in the control.



设置此属性时,指定的单元格不在 DataGridView 中。The specified cell when setting this property is not in the DataGridView.

当设置此属性时,指定的单元格的 RowIndexColumnIndex 属性值为 -1,指示它为标题单元格或共享单元格。The specified cell when setting this property has a RowIndex or ColumnIndex property value of -1, indicating that it is a header cell or a shared cell.

- 或 --or- 当设置此属性时,指定的单元格的 Visible 属性值为 falseThe specified cell when setting this property has a Visible property value of false.


下面的代码示例演示如何确保当前单元格在排序后可见。The following code example illustrates how to ensure that the current cell is visible after sorting. 此代码仅适用于未绑定的 DataGridView 控件。This code works only with an unbound DataGridView control. 如果将 @no__t 0 控件绑定到外部数据源,则在排序时不会自动保留当前单元格。With a DataGridView control bound to an external data source, the current cell is not automatically persisted when sorting.

若要运行此示例,请将以下代码粘贴到包含名为 @no__t 的 @no__t 0 的窗体中。To run this example, paste the following code into a form that contains a DataGridView named dataGridView1. 在C#中,还必须将 Sorted 事件连接到事件处理程序。In C#, you must also connect the Sorted event to the event handler.

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


您可以使用此属性来确定哪个单元格位于控件中当前显示的第一行和第一列中。You can use this property to determine which cell is in the first row and column currently displayed in the control. 通常,这是在左上角,但对于从右到左的语言,它在右上角。Typically, this is in the upper left corner, but for right-to-left languages, it is in the upper right corner. 您还可以将此属性设置为将控件滚动到指定的单元格。You can also set this property to scroll the control to the indicated cell.