BindingSource::Sort Property
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)
Property Value
Type: System::String^A case-sensitive string containing the column name followed by "ASC" (for ascending) or "DESC" (for descending). The default is null.
The Sort 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 Sort property will change the internal list depending on its type:
If the list is of type IBindingList, the IBindingList::SortProperty and IBindingList::SortDirection properties are set in the internal list.
If the list is of type IBindingListView, the IBindingListView::SortDescriptions property is set.
The internal list's sort properties are only changed when the sort string is not null. 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 Sort property will persist when the data source changes.
The following example shows how to use the Sort 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 Sort 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.
Available since 2.0