指定列值相同,纵向合并:
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)