ultraGrid 定制单元格合并逻辑

来源:互联网 发布:淘宝账号哪里买 编辑:程序博客网 时间:2024/06/05 09:05

1.在初始化表格中进行的设置

e.Layout.Bands[0].Columns["EXEC_RESULT"].MergedCellStyle = MergedCellStyle.Always;

e.Layout.Bands[0].Columns["EXEC_RESULT"].MergedCellEvaluator = new CustomMergedCellEvaluator();

2.设置合并行的逻辑

        public class CustomMergedCellEvaluator :IMergedCellEvaluator
        {
            public CustomMergedCellEvaluator() { }
            // 合并日期相同的单元格(无需时间精确相同)
            public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2,UltraGridColumn column)  //控件自带的方法,会自动进行调用,column为初始化中设置的行
            {
                string date1 = (string)row1.GetCellValue(column);//上边设置的列column->为EXEC_RESULT
                string date2 = (string)row2.GetCellValue(column);
                string comb1 = (string)row1.GetCellValue("COMB_NO");
                string comb2 = (string)row2.GetCellValue("COMB_NO");
                DateTime time1 = (DateTime)row1.GetCellValue("USE_TIME");
                DateTime time2 = (DateTime)row2.GetCellValue("USE_TIME");
                return (date1 == date2)&&(comb1==comb2)&&(time1==time2);
            }

        }


从帮助手册中摘录出来的原文

ShouldCellsBeMerged Method

Returns true if the cells of row1 and row2 associated with the column should be merged.
Syntax
  • Visual Basic
  • C#
bool ShouldCellsBeMerged(    UltraGridRow row1,   UltraGridRow row2,   UltraGridColumn column)
'Declaration Function ShouldCellsBeMerged( _   ByVal row1 As UltraGridRow, _   ByVal row2 As UltraGridRow, _   ByVal column As UltraGridColumn _) As Boolean
 

Parameters

row1
An UltraGridRow
row2
An UltraGridRow
column
The UltraGridColumn

using Infragistics.Shared;using Infragistics.Win;using Infragistics.Win.UltraWinGrid;using System.Diagnostics;                private class CustomMergedCellEvaluator : Infragistics.Win.UltraWinGrid.IMergedCellEvaluator                {                        public bool ShouldCellsBeMerged( UltraGridRow row1, UltraGridRow row2, UltraGridColumn column )                        {                                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;                        }                }                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 speficy custom logic for                        // merging cells.            e.Layout.Bands[0].Columns["ShipDate"].MergedCellEvaluator = new CustomMergedCellEvaluator( );                }

0 0
原创粉丝点击