Export (0) Print
Expand All

DataGridViewSortCompareEventArgs Class

Provides data for the SortCompare event.

System::Object
  System::EventArgs
    System.ComponentModel::HandledEventArgs
      System.Windows.Forms::DataGridViewSortCompareEventArgs

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ref class DataGridViewSortCompareEventArgs : public HandledEventArgs

The DataGridViewSortCompareEventArgs type exposes the following members.

  NameDescription
Public methodDataGridViewSortCompareEventArgsInitializes a new instance of the DataGridViewSortCompareEventArgs class.
Top

  NameDescription
Public propertyCellValue1Gets the value of the first cell to compare.
Public propertyCellValue2Gets the value of the second cell to compare.
Public propertyColumnGets the column being sorted.
Public propertyHandledGets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. (Inherited from HandledEventArgs.)
Public propertyRowIndex1Gets the index of the row containing the first cell to compare.
Public propertyRowIndex2Gets the index of the row containing the second cell to compare.
Public propertySortResultGets or sets a value indicating the order in which the compared cells will be sorted.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

You can handle the SortCompare event to provide custom sorting. This event occurs only when the DataGridView::DataSource property is not set and the DataGridView::VirtualMode property is set to false. This event occurs once for each pair of cells in the column being sorted. It occurs only when the user clicks the header of a column with a DataGridViewColumn::SortMode property value of Automatic, or when you call the DataGridView::Sort(DataGridViewColumn, ListSortDirection) overload. When this event occurs for a column with a DataGridViewColumn::SortMode property value of Programmatic, you must display the sorting glyph yourself through the DataGridViewColumnHeaderCell::SortGlyphDirection property.

You can use this event to sort rows using the cell values in one column or in multiple columns. Use the CellValue1 and CellValue2 properties to compare cell values in the column specified in the Column property. Use the RowIndex1 and RowIndex2 properties to access values in other columns through the DataGridView::Rows collection.

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft