A SortDirection value indicating the direction in which the values contained in the column are sorted. By default, SortDirection.None.
Member
Description
None
The column is not sorted.
Ascending
The column's values are sorted in an ascending direction.
Descending
The column's values are sorted in a descending direction.
Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated
otherwise.
The following example demonstrates how to sort the data items in ascending order according to the values of the ShipCountry column.The following example demonstrates how to provide a custom sort comparer that sorts addresses. The AddressComparer class (provided below) will first sort addresses which begin with numeric values by street name and then civic number. Address that do not have a civic number will be sorted alphabetically.The following code provides the implementation of the AddressComparer class.The following code provides the implementation of the AddressComparer class.
Imports System
Imports System.Collections
Imports System.Data
Namespace Xceed.Wpf.Documentation
PublicClass AddressComparer
Implements IComparer
PublicSubNew()
End SubPublicFunctionCompare( x AsObject, y AsObject ) AsIntegerImplements IComparer.Compare
Dim stringX AsString = CType( x, String )
Dim stringY AsString = Ctyle( y, String )
Const digits AsString = "0123456789"If( ( digits.IndexOf( stringX( 0 ) ) >= 0 ) And ( digits.IndexOf( stringY( 0 ) ) >= 0 ) ) ThenDim index AsInteger = 0
Dim xNumber As System.Text.StringBuilder = New System.Text.StringBuilder()
While( ( index < stringX.Length ) And ( digits.IndexOf( stringX( index ) ) >= 0 ) )
xNumber.Append( stringX( index ) )
index++
EndWhile
index = 0
Dim yNumber As System.Text.StringBuilder = New System.Text.StringBuilder()
While( ( index < stringY.Length ) And ( digits.IndexOf( stringY( index ) ) >= 0 ) )
yNumber.Append( stringY( index ) )
index++
EndWhileDim xValue = Long.Parse( xNumber.ToString() )
Dim yValue AsLong = Long.Parse( yNumber.ToString() )
If( xValue > yValue ) ThenReturn 1
EndIfIf( xValue < yValue ) ThenReturn -1
EndIfReturn stringX.CompareTo( stringY )
ElseReturn stringX.CompareTo( stringY )
EndIfEnd FunctionEnd ClassEnd Namespace
using System;
using System.Collections;
using System.Data;
namespace Xceed.Wpf.Documentation
{
publicclass AddressComparer: IComparer
{
public AddressComparer()
{
}
int IComparer.Compare( object x, object y )
{
string stringX = ( string )x;
string stringY = ( string )y;
conststring digits = "0123456789";
if( ( digits.IndexOf( stringX[ 0 ] ) >= 0 ) && ( digits.IndexOf( stringY[ 0 ] ) >= 0 ) )
{
int index = 0;
System.Text.StringBuilder xNumber = new System.Text.StringBuilder();
while( ( index < stringX.Length ) && ( digits.IndexOf( stringX[ index ] ) >= 0 ) )
{
xNumber.Append( stringX[ index ] );
index++;
}
index = 0;
System.Text.StringBuilder yNumber = new System.Text.StringBuilder();
while( ( index < stringY.Length ) && ( digits.IndexOf( stringY[ index ] ) >= 0 ) )
{
yNumber.Append( stringY[ index ] );
index++;
}
long xValue = long.Parse( xNumber.ToString() );
long yValue = long.Parse( yNumber.ToString() );
if( xValue > yValue )
return 1;
if( xValue < yValue )
return -1;
return stringX.CompareTo( stringY );
}
else
{
return stringX.CompareTo( stringY );
}
}
}
}
Requirements
Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2