惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
博客园 - 【当耐特】
D
Docker
Y
Y Combinator Blog
L
LangChain Blog
博客园 - 三生石上(FineUI控件)
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
B
Blog
The GitHub Blog
The GitHub Blog
腾讯CDC
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
爱范儿
爱范儿
A
About on SuperTechFans
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 木人(我现在不是老大)

ERP系统的专业化发展趋势 讨厌的real和float数据 Svcutil使用点滴 windows server2003企业版64位安装sql server2008企业版64位 水晶报表使用push模式(2) 水晶报表使用push模式(1) SQL SERVER2000存储过程调试 读书笔记 UltraGrid(15) 读书笔记 UltraGrid(14) 读书笔记 UltraGrid(12) 读书笔记 UltraGrid(11) 读书笔记 UltraGrid(10) 读书笔记 UltraGrid(9) 读书笔记 UltraGrid(8) 读书笔记 UltraGrid(7) 读书笔记 UltraGrid(6) 读书笔记 UltraGrid(5) 读书笔记 UltraGrid(4) 读书笔记 UltraGrid(3)
读书笔记 UltraGrid(16)
木人(我现在不是老大) · 2012-02-25 · via 博客园 - 木人(我现在不是老大)

单元格合并
当使用grid列示数据时,如果某一行某列数据和上一行的对应列数据相同时,我们想把该列的显示隐含。
所有band中的所有列。
this.ultraGrid1.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Always
其值还可以是:
OnlyWhenSorted:只在排序时候合并
Never:从不合并

也可以针对具体的列来设置,如:
this.ultraGrid1.DisplayLayout.Bands[1].Columns["SpecWth"].MergedCellStyle = MergedCellStyle.Never;
合并可以按文本相同或者值相同,如:
this.ultraGrid1.DisplayLayout.Bands[1].Columns["SpecWth"].MergedCellEvaluationType = MergedCellEvaluationType.MergeSameText;

但有时这种合并还是不能满足我们的要求,那我们可以自定义条件合并即可。
实现如下:
public class CustomMergedCellEvaluator : IMergedCellEvaluator
{
        UltraGridColumn[] ugcs;
        public CustomMergedCellEvaluator(UltraGridColumn[] keys)
        {
            this.ugcs = keys;
        }

        public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column)
        {
            bool keyIsSame = KeyIsSame(row1, row2, this.ugcs);
            if (keyIsSame == true)
                return row1.Cells[column].Value.ToString () == row2.Cells[column].Value.ToString();
            else
                return false;
        }

        private bool KeyIsSame(UltraGridRow row1, UltraGridRow row2, UltraGridColumn[] keys)
        {
           //定义合并的逻辑
            return keyIsSame;
        }
}

这时我们在column中设置如下,即可按我们的条件合并了。
ustomMergedCellEvaluator cmce = new CustomMergedCellEvaluator(new UltraGridColumn[]{ultraGrid1.DisplayLayout.Bands[1].Columns[0],ultraGrid1.DisplayLayout.Bands[1].Columns[1]});
column.MergedCellEvaluator = cmce;
column.MergedCellStyle = MergedCellStyle.Always;
column.MergedCellEvaluationType = MergedCellEvaluationType.MergeSameText;
其实现也就如此的简单。