The System.Globalization.CultureInfo to supply to the converter.
Return Value
An object representing the group name for the specified item.
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. The example results in the group being present at initial loading; also, when removing and re-adding the group, the custom group description is not triggered. See below for an alternative approach to avoid this.
The implementation for the custom sort comparer assigned to the group description's SortComparer property is provided below.
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Xceed.Wpf.DataGrid
Imports System.Collections
Imports System.Globalization;
Namespace Xceed.Wpf.Documentation
PublicClass AlphabeticalGroupDescription
Inherits DataGridGroupDescription
PublicSubNew()
MyBase.New()
End SubPublicSubNew(ByVal propertyName AsString)
MyBase.New(propertyName)
End SubPublicOverridesFunction GroupNameFromItem(ByVal item AsObject, _
ByVal level AsInteger, _
ByVal culture As CultureInfo) AsObjectDim value AsObject = MyBase.GroupNameFromItem(item, level, culture)
TryDim content AsString = Convert.ToString(value)
value = content.ToUpper().Substring(0, 1)
Catch e1 As InvalidCastException
EndTryReturn value
End FunctionEnd ClassEnd Namespace
The following code provides the implementation for the custom sort comparer that is used to sort, by vowels then consonants, the group descriptions create above.
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Collections
Namespace Xceed.Wpf.Documentation
PublicClass ConsonantVowelComparer
Implements IComparer
PublicSubNew()
End SubPublicFunctionCompare(ByVal x AsObject, _
ByVal y AsObject) AsIntegerImplements IComparer.Compare
If (Typeof x IsString) AndAlso (Typeof y IsString) ThenDim xString AsString = x.ToString().ToLowerInvariant()
Dim yString AsString = y.ToString().ToLowerInvariant()
Dim isXVowel AsBoolean = m_vowels.Contains(xString)
Dim isYVowel AsBoolean = m_vowels.Contains(yString)
If isXVowel Xor isYVowel ThenIf isXVowel ThenReturn -1
ElseReturn 1
EndIfEndIfReturnString.Compare(xString, yString)
EndIfThrowNew ArgumentException()
End FunctionPrivateConst m_vowels AsString = "aeiouy"End ClassEnd Namespace
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 example results in the group being present at initial loading; also, when removing and re-adding the group, the custom group description is not triggered. See below for an alternative approach to avoid this.
The implementation for the custom sort comparer assigned to the group description's SortComparer property is provided below.
using System;
using System.Collections.Generic;
using System.Text;
using Xceed.Wpf.DataGrid;
using System.Collections;
namespace Xceed.Wpf.Documentation
{
publicclass AlphabeticalGroupDescription : DataGridGroupDescription
{
public AlphabeticalGroupDescription()
: base()
{
}
public AlphabeticalGroupDescription( string propertyName )
: base( propertyName )
{
}
publicoverrideobject 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;
}
}
}
The following code provides the implementation for the custom sort comparer that is used to sort, by vowels then consonants, the group descriptions create above.
The first example results in the group being present at initial loading; also, when removing and re-adding the group, the custom GroupDescription is not triggered. But by adding the custom GroupDescription directly to the Column, data is not grouped until the end-user drags the column to create the group, and this occurs each time the end-user performs the operation.
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