GridControl自定义合并单元格 多个条件同时满足

示例1:转载自:http://www.cnblogs.com/ManchesterUnitedFootballClub/p/4601131.html

上面的示例为根据一个条件判断是否合并相同单元格。

下面是我看了上面的示例,根据自己的需求写的根据多个条件合并单元格,方法大同小异:

示例结果图:

《GridControl自定义合并单元格 多个条件同时满足》

代码:

 private void Form16_Load ( object sender ,EventArgs e )
        {
            //模拟数据集
            DataTable dt = new DataTable( );
            dt.Columns.Add( "A1" );
            dt.Columns.Add( "A2" );
            dt.Columns.Add( "A3" );
            dt.Columns.Add( "A4" );
            dt.Rows.Add( "测试001" ,"数据001" ,"样式001" ,"1" );
            dt.Rows.Add( "测试001" ,"数据004" ,"样式006" ,"1" );
            dt.Rows.Add( "测试001" ,"数据002" ,"样式003" ,"1" );
            dt.Rows.Add( "测试001" ,"数据002" ,"样式003" ,"2" );
            dt.Rows.Add( "测试001" ,"数据001" ,"样式001" ,"4" );
            dt.Rows.Add( "测试001" ,"数据001" ,"样式002" ,"4" );
            this.gridControl1.DataSource = dt;
        }
        /// <summary>
        /// 根据A2+A3的值是否相同  合并单元格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView1_CellMerge ( object sender ,DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e )
        {
            int row1 = e.RowHandle1;
            int row2 = e.RowHandle2;
            string value1 = gridView1.GetDataRow( row1 )["A2"].ToString( );
            string value2 = gridView1.GetDataRow( row2 )["A2"].ToString( );
            string value3 = gridView1.GetDataRow( row1 )["A3"].ToString( );
            string value4 = gridView1.GetDataRow( row2 )["A3"].ToString( );
            if ( value1+value3 != value2+value4 )
            {
                e.Handled = true;
            }
        }

    原文作者:独孤薄荷
    原文地址: https://blog.csdn.net/u011871201/article/details/52809047
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞