Export (0) Print
Expand All
Expand Minimize

DataGridView.Sorted Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when the DataGridView control completes a sorting operation.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event EventHandler Sorted
/** @event */
public void add_Sorted (EventHandler value)

/** @event */
public void remove_Sorted (EventHandler value)

JScript supports the use of events, but not the declaration of new ones.

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 handling events, see Consuming Events.

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.

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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft