DataGridViewSortCompareEventHandler Delegate
Represents the method that will handle the SortCompare event of a DataGridView control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration Public Delegate Sub DataGridViewSortCompareEventHandler ( _ sender As Object, _ e As DataGridViewSortCompareEventArgs _ ) 'Usage Dim instance As New DataGridViewSortCompareEventHandler(AddressOf HandlerMethod)
Parameters
- sender
- Type: System.Object
The source of the event.
- e
- Type: System.Windows.Forms.DataGridViewSortCompareEventArgs
A DataGridViewSortCompareEventArgs that contains the event data.
When you create a DataGridViewSortCompareEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see Events and Delegates.
The following code example demonstrates the use of SortCompare in a multiple column sort. This example is part of a larger example provided in How to: Customize Sorting in the Windows Forms DataGridView Control.
Private Sub DataGridView1_SortCompare( _ ByVal sender As Object, ByVal e As DataGridViewSortCompareEventArgs) _ Handles DataGridView1.SortCompare ' Try to sort based on the contents of the cell in the current column. e.SortResult = System.String.Compare(e.CellValue1.ToString(), _ e.CellValue2.ToString()) ' If the cells are equal, sort based on the ID column. If (e.SortResult = 0) AndAlso Not (e.Column.Name = "ID") Then e.SortResult = System.String.Compare( _ DataGridView1.Rows(e.RowIndex1).Cells("ID").Value.ToString(), _ DataGridView1.Rows(e.RowIndex2).Cells("ID").Value.ToString()) End If e.Handled = True End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.