This documentation is archived and is not being maintained.

DataView.Sort Property

Gets or sets the sort column or columns, and sort order for the DataView.

[Visual Basic]
Public Property Sort As String
[C#]
public string Sort {get; set;}
[C++]
public: __property String* get_Sort();
public: __property void set_Sort(String*);
[JScript]
public function get Sort() : String;
public function set Sort(String);

Property Value

A string containing the column name followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted ascending by default. Multiple columns can be separated by commas.

Remarks

For more information, see Creating and Using DataViews.

Example

[Visual Basic, C#, C++] The following example instructs the DataView to sort the table by two columns.

[Visual Basic] 
Private Sub SortByTwoColumns()
   ' Get the DefaultViewManager of a DataTable.
   Dim myDataView As DataView
   myDataView = DataTable1.DefaultView
   ' By default, the first column sorted ascending.
   myDataView.Sort = "State, ZipCode DESC"
End Sub

[C#] 
private void SortByTwoColumns()
{
   // Get the DefaultViewManager of a DataTable.
   DataView myDataView = DataTable1.DefaultView;
   // By default, the first column sorted ascending.
   myDataView.Sort = "State, ZipCode DESC";
}

[C++] 
private:
 void SortByTwoColumns()
 {
    // Get the DefaultViewManager of a DataTable.
    DataView* myDataView = DataTable1->DefaultView;
    // By default, the first column sorted ascending.
    myDataView->Sort = S"State, ZipCode DESC";
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataView Class | DataView Members | System.Data Namespace | RowFilter | Expression

Show: