IGroupByEvaluatorインターフェイスは、行をグループ化するためのカスタムロジックを供給するために使用されます。GroupByMode 設定のどれもがユーザーのニーズを満たさない場合、カスタムグルーピングを実行するために GroupByEvaluator を供給できます。グループ化の基準がソートの基準と一致しない場合、IGroupByEvaluatorEx インターフェイスを実装する必要があります。IGroupByEvaluatorEx はこれから派生し、行をソートするための追加 Compare メソッドを提供します。
以下の例はIGroupByEvaluatorの実装方法を示し、行は文字列フィールドの最初の2文字ずつグループ化されます。
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; } }