DataGridView.Sorted 事件


DataGridView 控件完成排序操作时发生。Occurs when the DataGridView control completes a sorting operation.

 event EventHandler ^ Sorted;
public event EventHandler Sorted;
member this.Sorted : EventHandler 
Public Custom Event Sorted As EventHandler 


下面的代码示例演示如何确保当前单元格在排序后可见。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


如果 VirtualMode 属性设置为 true,并且控件按未绑定的列排序,则不会发生此事件。This event does not occur when the VirtualMode property is set to true and the control is sorted by an unbound column.

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.