Click here to Skip to main content
13,665,440 members
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 20 Dec 2006

a cool and universal datagrid merger

, 20 Dec 2006
Rate this:
Please Sign up or sign in to vote.
a cool and universal datagrid merger, you can merge multi-headers and datagrid body

Sample Image - GridMerger.gif


 It is a cool DataGrid Merger, it is very simple and useful.

 Only use a few code, you can merge datagrid's Header and body.

 I hope it is helpful  to you!    

Using the code  

 protected void Page_Load(object sender, EventArgs e) 
  DataTable dt = new DataTable(); 
  AddTableColumn(dt, "f1", null); 
  AddTableColumn(dt, "f2", "income|f2"); 
  AddTableColumn(dt, "f3", "income|f3"); 
  AddTableColumn(dt, "f4", "income|Last Year|f4");
  AddTableColumn(dt, "f5", "income|Last Year|f5"); 
  AddTableColumn(dt, "f6", null); 
  AddTableColumn(dt, "f7", "outcome|f7");
  AddTableColumn(dt, "f8", "outcome|f9");
  for (int r = 1; r <= 6; r++) 
    DataRow dr = dt.NewRow(); 
    dr["f1"] = "" + (r / 4); 
    dr["f2"] = "" + (r / 2);
    for (int col = 3; col <= dt.Columns.Count; col++) 
      dr["f" + col] = "" + (col*r); 
  DataGrid1.DataSource = dt; 
  foreach (DataColumn dataColumn in dt.Columns)
     BoundColumn column = new BoundColumn();
     column.DataField = dataColumn.ColumnName; 
     column.HeaderText = dataColumn.Caption == null ? dataColumn.ColumnName : dataColumn.Caption; 
  DfawWeb.CtrlUtil.DataGridMerger merger = new DfawWeb.CtrlUtil.DataGridMerger(DataGrid1);
    merger.AddMergeColumn("f2"); //  
    merger.AddMergeColumn("f1"); //   
public interface IMatrix 
  int RowCount { get; } 
  int ColumnCount { get; } 
  object GetCellValue(int row, int col);

 public class MergeCell
   public System.Drawing.Rectangle Bounds; 
   public object Value; // &#20540; 

 public class MergeCellList : CollectionBase 
  public enum MergeModeEnum 
    RowCol = 0,
void dataGrid_ItemCreated(object sender, DataGridItemEventArgs e)
            if (ListItemType.Item == e.Item.ItemType || ListItemType.AlternatingItem == e.Item.ItemType)
                if (canMergColHash != null && canMergColHash.Count > 0)  //&#21512;&#24182;&#34920;&#20307;
                    e.Item.SetRenderMethodDelegate(new RenderMethod(BodyMergeRenderMethod));
            if (cellList != null && ListItemType.Header == e.Item.ItemType)  // &#21512;&#24182;&#34920;&#22836;
                e.Item.SetRenderMethodDelegate(new RenderMethod(HeaderMergeRenderMethod));

Points of Interest

  more know, please Visit:


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWhat is EasyReport? Pin
Prasad Khandekar21-Dec-06 23:30
memberPrasad Khandekar21-Dec-06 23:30 
AnswerRe: What is EasyReport? Pin
Wangyim22-Dec-06 19:57
memberWangyim22-Dec-06 19:57 
EasyReport is a Report of, it is very simple and powerful.
It contains three parts:report designer \report serve programme and the API
support Winform and is suitable for two kinds of user:the final user and the software provider. It can be used as an independent programme and a part of one programme as well.The report format can be saved in the database ,and you can easily make a repor just move the target word with the mouse .EasyReport supports different databases such as
SqlServer, Oracle,Access and so on.

I'll be glad to talk about the details of my EasyReport with you later.
Smile | :)


GeneralYou are so cool &#65306;) Pin
YU-TIEN21-Dec-06 18:42
memberYU-TIEN21-Dec-06 18:42 
GeneralRe: You are so cool &#65306;) Pin
Wangyim21-Dec-06 21:56
memberWangyim21-Dec-06 21:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180810.1 | Last Updated 21 Dec 2006
Article Copyright 2006 by Wangyim
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid