BindingSource::Sort Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the column names used for sorting, and the sort order for viewing the rows in the data source.

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

public:
property String^ Sort {
	String^ get();
	void set(String^ value);
}

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:

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.

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

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.

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

.NET Framework
Available since 2.0
Return to top
Show: