Xceed DataGrid for WPF v7.2 Documentation
SortComparer Property (DataGridGroupDescription)
Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > DataGridGroupDescription Class : SortComparer Property
Gets or sets the data comparer that will be used to sort the groups in a grid.
Syntax
'Declaration
 
Public Property SortComparer As IComparer
'Usage
 
Dim instance As DataGridGroupDescription

Dim value As IComparer

 

instance.SortComparer = value

 

value = instance.SortComparer
public IComparer SortComparer {get; set;}

Property Value

The Comparer that will be used to sort the groups in a grid. Can be a null reference (Nothing in Visual Basic).
Remarks
If a null reference (Nothing in Visual Basic), the default data-type comparer will be used.
Example

All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.

This example demonstrates how to create a custom group description by deriving from the DataGridGroupDescription class and overriding the GroupNameFromItem method. The custom group description will group items according to the first letter in the value received as a parameter.This example demonstrates how to create a custom group description by deriving from the DataGridGroupDescription class and overriding the GroupNameFromItem method. The custom group description will group items according to the first letter in the value received as a parameter.The following code demonstrates how to use the custom group description by adding it to the DataGridCollectionViewSource's GroupDescriptions property.
Imports System

Imports System.Collections.Generic

Imports System.Text

Imports Xceed.Wpf.DataGrid

Imports System.Collections

Imports System.Globalization;



Namespace Xceed.Wpf.Documentation

  Public Class AlphabeticalGroupDescription



         Inherits DataGridGroupDescription

    Public Sub New()

      MyBase.New()

    End Sub



    Public Sub New(ByVal propertyName As String)

     MyBase.New(propertyName)

    End Sub

    Public Overrides Function GroupNameFromItem(ByVal item As Object, _

                                                ByVal level As Integer, _

                                                ByVal culture As CultureInfo) As Object

      Dim value As Object = MyBase.GroupNameFromItem(item, level, culture)

      Try

        Dim content As String = Convert.ToString(value)

        value = content.ToUpper().Substring(0, 1)

      Catch e1 As InvalidCastException

      End Try



      Return value

    End Function

  End Class

End Namespace
using System;

using System.Collections.Generic;

using System.Text;

using Xceed.Wpf.DataGrid;

using System.Collections;



namespace Xceed.Wpf.Documentation

{



  public class AlphabeticalGroupDescription : DataGridGroupDescription

  {

    public AlphabeticalGroupDescription()

      : base()

    {

    }



    public AlphabeticalGroupDescription( string propertyName )

      : base( propertyName )

    {

    }

   



    public override object GroupNameFromItem( object item, int level,

                                              System.Globalization.CultureInfo culture )

    {

      object value = base.GroupNameFromItem( item, level, culture );

      try

      {

        string content = Convert.ToString( value );

        value = content.ToUpper().Substring( 0, 1 );



      }

      catch( InvalidCastException )

      {

      }

      return value;

    }

  }

}
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"

     xmlns:local="clr-namespace:Xceed.Wpf.Documentation">

  <Grid.Resources>      

    <local:ConsonantVowelComparer x:Key="consonantVowelComparer"/>



    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"

                                       Source="{Binding

                                                Source={x:Static Application.Current},

                                                Path=Orders}">



     <xcdg:DataGridCollectionViewSource.GroupDescriptions>

       <local:AlphabeticalGroupDescription PropertyName="ShipCountry"

                                SortComparer="{StaticResource consonantVowelComparer}"/>

     </xcdg:DataGridCollectionViewSource.GroupDescriptions>

    </xcdg:DataGridCollectionViewSource>

  </Grid.Resources>

  <xcdg:DataGridControl x:Name="OrdersGrid"

                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>

</Grid>
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

See Also

Reference

DataGridGroupDescription Class
DataGridGroupDescription Members