UltraWinGrid是包含在infragistics for Windows Forms下的一款强大的表格控件,使用UltraWinGrid可以轻松实现单元格的合并,在很多时候需要自定义一些合并的规则或者逻辑,当符合这种逻辑的单元格进行合并,UltraWinGrid为开发人员提供了IMergedCellEvaluator接口,专门用于自定义单元格合并,具体使用方法请参考下面的事例:
using Infragistics.Win.UltraWinGrid;
public class CustomMergedCellEvaluator:
Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
{
public CustomMergedCellEvaluator()
{
}
public bool ShouldCellsBeMerged(UltraGridRow row1,
UltraGridRow row2, UltraGridColumn column)
{
// Test to make sure the Type is not DBNull since we allow the ShippedDate to be null
if (row1.GetCellValue(column).GetType().ToString() != "System.DBNull" && row2.GetCellValue(column).GetType
().ToString() != "System.DBNull")
{
DateTime date1 = (DateTime)row1.GetCellValue(column);
DateTime date2 = (DateTime)row2.GetCellValue(column);
// Merge cells according to the date portions of the underlying DateTime cell
// values, ignoring any time portion. For example, "1/1/2004 10:30 AM" will be
// merged with "1/1/2004 1:15 AM" since the dates are the same.
return date1.Date == date2.Date;
}
else
return false;
}
}
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
// Set the MergedCellStyle property to enable the merged cell functionality.
// MergedCellStyle also specifies which columns will merge their cells.
e.Layout.Override.MergedCellStyle = MergedCellStyle.Always;
// MergedCellEvaluator property can be used to specify custom logic for
// merging cells.
e.Layout.Bands[0].Columns["ShippedDate"].MergedCellEvaluator = new CustomMergedCellEvaluator();
}