DataGridView.Sorted Event

Definition

Occurs when the DataGridView control completes a sorting operation.

C#
public event EventHandler Sorted;
C#
public event EventHandler? Sorted;

Event Type

Examples

The following code example illustrates how to ensure that the current cell is visible after sorting. This code works only with an unbound DataGridView control. With a DataGridView control bound to an external data source, the current cell is not automatically persisted when sorting.

To run this example, paste the following code into a form that contains a DataGridView named dataGridView1. In C#, you must also connect the Sorted event to the event handler.

C#
private void dataGridView1_Sorted(object sender, EventArgs e)
{
    this.dataGridView1.FirstDisplayedCell = this.dataGridView1.CurrentCell;
}

Remarks

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.

Applies to

Product 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, 10

See also