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)
            {
            }
        }
    }
}

《IOS视频录制,本地视频播放,剪切,合并》系列(1)本地视频播放

前言: Recently 公司项目里用到了一些视频的剪辑操作,所以就找了很多这方面的资料,发现了一个问题就是国内这方面的资料非常少 =_=|| ,有的也只是一些很基础的知识讲解和demo,能够运行不...
  • u012320459
  • u012320459
  • 2015年12月17日 17:58
  • 1069

Delphi 转EXCEL 合并单元格解决方案

废话少说先上传代码,自己看吧! procedure TForm1.Button10Click(Sender: TObject); var   FExcel:Variant;   FWorkbo...
  • Trassion
  • Trassion
  • 2014年09月13日 11:30
  • 4371

protobuf的简单应用,json和protocol Buffer的转换简单例子

protobuf的简单应用,json和protocol Buffer的转换简单例子
  • liangrui1988
  • liangrui1988
  • 2015年04月27日 17:53
  • 3452

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...
  • jzt_designer
  • jzt_designer
  • 2013年04月27日 10:32
  • 885

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...
  • u010069742
  • u010069742
  • 2013年06月19日 13:48
  • 1063

How to Troubleshoot Grid Infrastructure Startup Issues [ID 1050908.1]

How to Troubleshoot Grid Infrastructure Startup Issues [ID 1050908.1]   ...
  • xujinyang
  • xujinyang
  • 2011年09月29日 18:59
  • 765

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...
  • tianlesoftware
  • tianlesoftware
  • 2011年04月26日 09:43
  • 5867

How to extend Magento Order Grid?

How to extend Magento Order Grid? 30th NOV 2010 | Posted by Domagoj Potkoci...
  • terry_water
  • terry_water
  • 2011年01月25日 22:52
  • 763

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...
  • xujinyang
  • xujinyang
  • 2011年09月29日 09:58
  • 894

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...
  • jzt_designer
  • jzt_designer
  • 2016年03月17日 17:28
  • 502
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to merge grid cells
举报原因:
原因补充:

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