Gets or sets the column names used for sorting, and the sort order for viewing the rows in the data source.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The property is a case-sensitive string that specifies the column names used to sort the rows, along with the sort direction. Columns are sorted ascending by default. Multiple columns can be separated by commas, such as "State, ZipCode DESC".
To support sorting, the underlying list must implement the IBindingList or IBindingListView interfaces. This capability can be queried through the SupportsSorting property. Multicolumn sorting is available when the SupportsAdvancedSorting property is true.
Setting the property will change the internal list depending on its type:
The internal list's sort properties are only changed when the sort string is not nullptr. The get accessor for this property will not retrieve the sort value of the internal list; instead, it will return the set accessor value. The value of the property will persist when the data source changes.
The following example shows how to use the property to perform basic sorting with a DataView. To run this example, paste the code into a Windows Form and call PopulateDataViewAndSort from the form's constructor or Load event-handling method. Your form should import the System.Xml and System.IO namespaces.
The following example shows how to use the property to perform advanced sorting with a DataView. To run this example, paste the code into a Windows Form and call PopulateDataViewAndAdvancedSort from the form's constructor or Load event-handling method. Your form should import the System.Xml and System.IO namespaces.
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)