Infragistics(R) NetAdvantage(R) Windows Forms
GroupByComparer Property
See Also  Example E-mail your feedback on this topic.
Infragistics.Win.UltraWinGrid Namespace > UltraGridColumn Class : GroupByComparer Property

Property used for specifying a custom comparer to sort group-by rows.

Syntax

Visual Basic (Declaration) 
Public Property GroupByComparer As IComparer
C# 
public IComparer GroupByComparer {get; set;}

Example

Following code shows how to sort group-by rows using custom sort criteria.

Visual BasicCopy Code
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid


    Private Class CustomGroupByRowsSorter
        Implements IComparer

        Private Function Compare(ByVal xObj As Object, ByVal yObj As Object) As Integer Implements IComparer.Compare
            Dim x As UltraGridGroupByRow = DirectCast(xObj, UltraGridGroupByRow)
            Dim y As UltraGridGroupByRow = DirectCast(yObj, UltraGridGroupByRow)

            ' Compare the group rows by the number of items they contain.
            Return x.Rows.Count.CompareTo(y.Rows.Count)
        End Function

    End Class

    Private Sub UltraGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles ultraGrid1.InitializeLayout
        ' Make sure the ViewStyleBand is set to OutlookGroupBy in order to be able
        ' to group rows.
        Me.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy
        Me.ultraGrid1.DisplayLayout.Bands(0).SortedColumns.Clear()

        Dim countryCol As UltraGridColumn = Me.ultraGrid1.DisplayLayout.Bands(0).Columns("Country")

        ' Group rows by country column.
        Me.ultraGrid1.DisplayLayout.Bands(0).SortedColumns.Add(countryCol, False, True)

        ' Assign the GroupByComparer to our custom group rows comparer which
        ' we defined above.
        countryCol.GroupByComparer = New CustomGroupByRowsSorter()
    End Sub
C#Copy Code
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;


		private class CustomGroupByRowsSorter : IComparer
		{
			public int Compare( object xObj, object yObj )
			{
				UltraGridGroupByRow x = (UltraGridGroupByRow)xObj;
				UltraGridGroupByRow y = (UltraGridGroupByRow)yObj;

				// Compare the group rows by the number of items they contain.
				return x.Rows.Count.CompareTo( y.Rows.Count );
			}
		}

		private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
		{
			// Make sure the ViewStyleBand is set to OutlookGroupBy in order to be able
			// to group rows.
			this.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
			this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Clear( );
			
			UltraGridColumn countryCol = this.ultraGrid1.DisplayLayout.Bands[0].Columns[ "Country" ];

			// Group rows by country column.
			this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Add( countryCol, false, true );

			// Assign the GroupByComparer to our custom group rows comparer which
			// we defined above.
			countryCol.GroupByComparer = new CustomGroupByRowsSorter( );
		}

Remarks

This IComparer instance will be used for sorting group-by rows associated with this column if this column were a group-by column.

See Also