Gridcontrol纵向/横向合并单元格

指定列值相同,纵向合并:

this.gridView1.OptionsView.AllowCellMerge = true;//启用合并列
// 启用指定合并列事件
this.gridView1.CellMerge += new DevExpress.XtraGrid.Views.Grid.CellMergeEventHandler(gridView1_CellMerge);

#region 合并指定的列
private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
{
     int rowHandle1 = e.RowHandle1;//合并列的第一行
     int rowHandle2 = e.RowHandle2;//合并列从1开始到最后行就是
     string strValue1 = this.gridView1.GetListSourceRowCellValue(rowHandle1, "age").ToString();//age:列名称
     string strValue2 = this.gridView1.GetListSourceRowCellValue(rowHandle2, "age").ToString();//age:列名称
     if (strValue1 != strValue2)
     {
         e.Merge = false; //值相同的2个单元格是否要合并在一起
         e.Handled = true; //合并单元格是否已经处理过,无需再次进行省缺处理
     }
 }
#endregion

指定列值相同,纵向合并

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraGrid.Columns;
 
namespace HorizontalMerging
{
    public partial class Form1 : Form
    {
        MyGridViewHandler ViewHandler = null;
        public Form1()
        {
            InitializeComponent();
            ViewHandler = new MyGridViewHandler(gridView1);
        }
 
        private DataTable CreateTable(int RowCount)
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值