日期:2014-05-17  浏览次数:21019 次

有用过DevExpress的Xtragrid的吗?合并单元格问题
有用过DevExpress的Xtragrid合并把一列中相同的都合并了,
例子:
name value
aa 1
aa 1
bb 1
合并为
name value
aa 1
空 空
bb 空
我想要的是
name value
aa 1
空 空
bb 1
也就是value也按name列合并

------解决方案--------------------
嗯,我说错了,
在gridview的cellmerge事件中下能实现,gridview中有3列对应,代码如下
C# code

        public Form1()
        {
            InitializeComponent();

            //Microsoft.CSharp.CSharpCodeProvider my = new CSharpCodeProvider();
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("c1"));
            dt.Columns.Add(new DataColumn("c2"));
            dt.Columns.Add(new DataColumn("c3"));
            DataRow dr = dt.NewRow();
            dr["c1"] = "r1c1";
            dr["c2"] = "r1c2";
            dr["c3"] = "r1c3";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["c1"] = "r2c1";
            dr["c2"] = "r1c2";
            dr["c3"] = "r1c3";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["c1"] = "r3c1";
            dr["c2"] = "r1c2";
            dr["c3"] = "r3c3";
            dt.Rows.Add(dr);

            this.gridControl1.DataSource = dt;

        }

        private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            //if (e.Column.FieldName== "c2")
            //{
            //    if (this.gridView1.GetDataRow(e.RowHandle1)["c3"].ToString() != this.gridView1.GetDataRow(e.RowHandle2)["c3"].ToString())
            //        e.Handled = true;
            //}
            //else if (e.Column.FieldName == "c3")
            //{
            //    if (this.gridView1.GetDataRow(e.RowHandle1)["c2"].ToString() != this.gridView1.GetDataRow(e.RowHandle2)["c2"].ToString())
            //        e.Handled = true;
            //}
            if ((this.gridView1.GetDataRow(e.RowHandle1)["c2"].ToString() != this.gridView1.GetDataRow(e.RowHandle2)["c2"].ToString())
                ||(this.gridView1.GetDataRow(e.RowHandle1)["c3"].ToString() != this.gridView1.GetDataRow(e.RowHandle2)["c3"].ToString()))
                e.Handled = true;
        }