Version

IGroupByEvaluator Interface

Interface to be used for determining how rows are grouped.
Syntax
'Declaration
 
Public Interface IGroupByEvaluator 
public interface IGroupByEvaluator 
Remarks

IGroupByEvaluator interface is used to supply custom logic for grouping rows. If none of the GroupByMode settings meet your needs, you can supply a GroupByEvaluator to perform custom grouping. If your grouping criteria is not consistent with the sorting criteria, then you may need to implement the IGroupByEvaluatorEx interface. IGroupByEvaluatorEx derives from this and exposes additional Compare method for sorting rows.

The following example shows how to implement a IGroupByEvaluator so that rows are grouped by the 1st 2 characters of a string field:

             private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
             {
                        // set the view style to outlook group by
                        e.Layout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
                
                Infragistics.Win.UltraWinGrid.UltraGridColumn column;
                
                // get the CompanyName column
                column = e.Layout.Bands[0].Columns["CompanyName"];
             
                // set the GroupByEvaluator on the column to an instance of MyGroupByEvaluator 
                column.GroupByEvaluator = new MyGroupByEvaluator();
             
                // set the column's HiddenWhenGroupBy property to false since we are
                // grouping by the 1st 2 characters of each string we want the full
                // company name to show in each row
                //
                column.HiddenWhenGroupBy = DefaultableBoolean.False;
             }
             
             public class MyGroupByEvaluator : Infragistics.Win.UltraWinGrid.IGroupByEvaluator
             {
                        public object GetGroupByValue( UltraGridGroupByRow groupbyRow, UltraGridRow row )
                        {
                                string val;
                
                                // get the default value from the groupbyRow
                                if (groupbyRow.Value == null )
                                        val = "";
                                else
                                        val = groupbyRow.Value.ToString();
            
                                // if it is longer than 2 characters truncate it
                                if ( val.Length > 2 )
                                        val = val.Substring( 0, 2 );
            
                                // Convert the string to uppercase for display 
                                // in the groupbyrow description.
                                return val.ToUpper();
                        }
            
                        public bool DoesGroupContainRow( UltraGridGroupByRow groupbyRow, UltraGridRow row )
                        {
                                // get the related cell's value as a string
                                string cellValue = row.Cells[groupbyRow.Column].Value.ToString();
            
                                // if it is longer than 2 characters truncate it
                                if ( cellValue.Length > 2 )
                                        cellValue = cellValue.Substring(0, 2);
            
                                // Do a case insensitive compare
                                return string.Compare(groupbyRow.Value.ToString(), cellValue, true) == 0;
                        }
             }
             
Example
Following code shows you how to group rows with a custom group-by code. It groups rows by the first two characters of the company name field. It implements IGroupByEvaluator interface and assigns an instance of it to the GroupByEvaluator property of ContactName column and then groups rows by it.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Public Class MyGroupByEvaluator
      Implements Infragistics.Win.UltraWinGrid.IGroupByEvaluator

      Private Function GetGroupByValue(ByVal groupbyRow As UltraGridGroupByRow, ByVal row As UltraGridRow) As Object Implements IGroupByEvaluator.GetGroupByValue

          Dim val As String

          ' Get the default value from the groupbyRow.
          If groupbyRow.Value Is Nothing Then
              val = ""
          Else
              val = groupbyRow.Value.ToString()
          End If

          ' If it is longer than 2 characters truncate it.
          If val.Length > 2 Then
              val = val.Substring(0, 2)
          End If

          ' Convert the string to uppercase for display in the group-by row's description.
          Return val.ToUpper()

      End Function

      Private Function DoesGroupContainRow(ByVal groupbyRow As UltraGridGroupByRow, ByVal row As UltraGridRow) As Boolean Implements IGroupByEvaluator.DoesGroupContainRow

          ' Get the related cell's value as a string.
          Dim cellValue As String = row.Cells(groupbyRow.Column).Value.ToString()

          ' If it is longer than 2 characters truncate it.
          If cellValue.Length > 2 Then
              cellValue = cellValue.Substring(0, 2)
          End If

          ' Do a case insensitive compare.
          Return 0 = String.Compare(groupbyRow.Value.ToString(), cellValue, True)
      End Function

  End Class

  Private Sub Button35_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button35.Click

      ' Set the view style to OutlookGroupBy to enable the outlook-group-by feature.
      Me.UltraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy

      ' Get the CompanyName column.
      Dim column As UltraGridColumn = Me.UltraGrid1.DisplayLayout.Bands(0).Columns("CompanyName")

      ' Set the GroupByEvaluator on the column to an instance of MyGroupByEvaluator.
      column.GroupByEvaluator = New MyGroupByEvaluator()

      ' Set the column's HiddenWhenGroupBy property to false since we are
      ' grouping by the 1st 2 characters of each string we want the full
      ' company name to show in each row.
      column.HiddenWhenGroupBy = DefaultableBoolean.False

      ' Now group the rows by the column.
      Me.UltraGrid1.DisplayLayout.Bands(0).SortedColumns.Add(column, False, True)

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

public class MyGroupByEvaluator : Infragistics.Win.UltraWinGrid.IGroupByEvaluator
{
	public object GetGroupByValue( UltraGridGroupByRow groupbyRow, UltraGridRow row )
	{

		string val;
		
		// Get the default value from the groupbyRow.
		if (groupbyRow.Value == null )
			val = "";
		else
			val = groupbyRow.Value.ToString();
	
		// If it is longer than 2 characters truncate it.
		if ( val.Length > 2 )
			val = val.Substring( 0, 2 );
	
		// Convert the string to uppercase for display in the group-by row's description.
		return val.ToUpper();

	}
	
	public bool DoesGroupContainRow( UltraGridGroupByRow groupbyRow, UltraGridRow row )
	{

		// Get the related cell's value as a string.
		string cellValue = row.Cells[groupbyRow.Column].Value.ToString();
	
		// If it is longer than 2 characters truncate it.
		if ( cellValue.Length > 2 )
			cellValue = cellValue.Substring(0, 2);
	
		// Do a case insensitive compare.
		return 0 == string.Compare(groupbyRow.Value.ToString(), cellValue, true);
	}

}

private void button35_Click(object sender, System.EventArgs e)
{

	// Set the view style to OutlookGroupBy to enable the outlook-group-by feature.
	this.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
	
	// Get the CompanyName column.
	UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns["CompanyName"];
	 
	// Set the GroupByEvaluator on the column to an instance of MyGroupByEvaluator 
	column.GroupByEvaluator = new MyGroupByEvaluator();
	 
	// Set the column's HiddenWhenGroupBy property to false since we are
	// grouping by the 1st 2 characters of each string we want the full
	// company name to show in each row.
	column.HiddenWhenGroupBy = DefaultableBoolean.False;

	// Now group the rows by the column.
	this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Add( column, false, true );

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, 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