How to merge grid cells

翻译 2015年11月19日 15:15:44


The sample illustrates the way to merge grid cells based on a custom-defined rule. To enable cell merging, it's necessary to set the GridView.OptionsView.AllowCellMerge property to true. If you don't want to merge some columns, set the GridColumn.OptionsColumn.AllowMerge property to false. A merging rule is defined using the GridView.CellMerge event.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;

namespace WindowsApplication93
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 100; i++)
                dataTable1.Rows.Add(new object[] {i %5, "Product " + i, i %7 });
            gridView1.OptionsView.AllowCellMerge = true;
            for (int i = 0; i < gridView1.Columns.Count; i++)
                if (gridView1.Columns[i].FieldName == "CategoryID")
                    gridView1.Columns[i].OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True;
                else
                    gridView1.Columns[i].OptionsColumn.AllowMerge =  DevExpress.Utils.DefaultBoolean.False;
        }

        private void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            GridView view = sender as GridView;
            try
            {
                if ((e.Column.FieldName == "CategoryID"))
                {
                    int value1 = Convert.ToInt32(view.GetRowCellValue(e.RowHandle1, e.Column));
                    int value2 = Convert.ToInt32(view.GetRowCellValue(e.RowHandle2, e.Column));

                    e.Merge = (value1 == value2);
                    e.Handled = true;
                    return;
                }
            }
            catch (Exception ex)
            {
            }
        }
    }
}

相关文章推荐

DevExpress 纵向合并GridControl单元格控制

在DevExpress中GridControl中合并单元格只需要设置 this.gridView1.OptionsView.AllowCellMerge = true; 列默认是可合并的,若设置某列不...
  • jjhua
  • jjhua
  • 2017年02月16日 21:08
  • 1333

How to: Host Controls in Windows Forms DataGridView Cells(介绍如何在datagridview中自定义列)

The DataGridView control provides several column types, enabling your users to enter and edit valu...

How to Troubleshoot Grid Infrastructure Startup Issues [ID 1050908.1]

How to Troubleshoot Grid Infrastructure Startup Issues [ID 1050908.1]   ...

How to install a patch on clusterware 11.2.0.1 into grid infrastructure home

When applying a needed patch to the Grid Infrastructure Home for ASM or CRS the opatch utility may e...

dephi tcxgrid How to Retrieve the Record Values for the Selected Grid Rows

Table Views of the ExpressQuantumGrid allow you to select one or more records. If you want to retrie...

How to Proceed from Failed 11gR2 Grid Infrastructure (CRS) Installation [ID 942166.1]

How to Proceed from Failed 11gR2 Grid Infrastructure (CRS) Installation [ID 942166.1] ...

Git: How To Revert A Branch Merge

This was a stumper for me a while back. Jason Meridth posted on reseting / reverting git commits a...

How to install a patch on clusterware 11.2.0.1 into grid infrastructure home

        When applying a needed patch to the Grid Infrastructure Home for ASM or CRS the opatch utili...

How to extend Magento Order Grid?

How to extend Magento Order Grid? 30th NOV 2010 | Posted by Domagoj Potkoci...

Git: How to revert a merge commit that's already pushed to remote branch?

revert a merge commit
  • wwq518
  • wwq518
  • 2016年08月10日 23:28
  • 181
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to merge grid cells
举报原因:
原因补充:

(最多只允许输入30个字)