自定义UltraWinGrid控件的列合并模式

/// <summary> /// 表示自定义UltraWinGrid控件的列合并模式(以显示文本合并) /// </summary> public class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator { private string primaryKey; /// <summary> /// 获取或设置合并列的主键列的绑定名称 /// </summary> public string PrimaryKey { get { return primaryKey; } set { primaryKey = value; } } /// <summary> /// CustomMergedCellEvaluator 的构造函数 /// </summary> /// <param name="primaryKey">主键列的绑定名称</param> public CustomMergedCellEvaluator(string primaryKey) { this.primaryKey = primaryKey; } #region IMergedCellEvaluator 成员 public bool ShouldCellsBeMerged(Infragistics.Win.UltraWinGrid.UltraGridRow row1, Infragistics.Win.UltraWinGrid.UltraGridRow row2, Infragistics.Win.UltraWinGrid.UltraGridColumn column) { //确认逻辑:如果是主键列,自动合并,否则通过联合主键来合并 if (column.MergedCellStyle == Infragistics.Win.UltraWinGrid.MergedCellStyle.Always) { if (string.IsNullOrEmpty(this.primaryKey)) { return row1.GetCellText(column) == row2.GetCellText(column); } if ((row1.GetCellValue(row1.Cells[this.primaryKey].Column).ToString() == row2.GetCellValue(row1.Cells[this.primaryKey].Column).ToString()) && (row1.GetCellText(column) == row2.GetCellText(column))) { return true; } } return false; } #endregion }

调用方法

private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { CustomMergedCellEvaluator merge = new CustomMergedCellEvaluator("TaskGroupID"); e.Layout.Bands[1].Columns["OrderCode"].MergedCellStyle = MergedCellStyle.Always; e.Layout.Bands[1].Columns["OrderCode"].MergedCellEvaluator = merge; }

阅读更多
换一批

没有更多推荐了,返回首页