Home › Forums › WinForms controls › Xceed Grid for WinForms › Custom grouping and sorting
-
AuthorPosts
-
#17801 |
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 implementation for the custom sort comparer assigned to the group description’s SortComparer property is provided below.
VB.NET
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 DataGridGroupDescriptionPublic Sub New()
MyBase.New()
End SubPublic Sub New(ByVal propertyName As String)
MyBase.New(propertyName)
End SubPublic 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 TryReturn value
C#
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 );
 Imported from legacy forums. Posted by Xceed admin (had 1341 views)
-
AuthorPosts
- You must be logged in to reply to this topic.