Click here to Skip to main content
Licence 
First Posted 14 Sep 2002
Views 155,993
Bookmarked 77 times

Adding "Merge cells" support to the MFC GridControl

By | 29 Dec 2002 | Article
Adding "Merge cells" support to the MFC GridControl.

Sample Image - gridcontrl.jpg

Sample Image - print.jpg

Introduction

This example demonstrates how to add "merge cells" ability to Chris Maunder's MFC Grid control (derived from CWnd).

The example modifies only two classes: CGridCellBase and CGridCtrl. In the class CGridCellBase ,the following four private member variables are added:

CCellRange m_MergeRange;
bool m_IsMergeWithOthers;
CCellID m_MergeCellID;
bool m_Hide;

Six public member functions are also added:

void UnMerge();
virtual bool IsShow() ;
virtual CCellRange GetMergeRange();
virtual bool IsMergeWithOthers();
virtual CCellID GetMergeCellID();
virtual void SetMergeCellID(CCellID cell);

In the class CGridCtrl, the following six public member functions are added:

CGridCellBase* GetCell(CCellID cell);
CCellID GetMergeCellID(CCellID cell);
void UnMergeSelectedCells();
void MergeSelectedCells();
void UnMergeCells(int nStartRow, int nStartCol, int nEndRow, int nEndCol);
void MergeCells(int nStartRow, int nStartCol, int nEndRow, int nEndCol);

Usage

  • Use CGridCtrl::MergeSelectedCells() and MergeCells() to merge the selected cells;
  • Use CGridCtrl::UnMergeSelectedCells() and UnMergeCells() to restore the selected cell to its original state.

History

  • 1.7 fixed the bug when merging in the corner, by Luther Bruck - 2002/12/31
  • 1.6 fixed the bug when resizing the merged row - 2002/11/20
  • 1.5 fixed the bug when resizing the merged column - 2002/11/18
  • 1.4 bug when printing merge cell across pages fixed - 2002/10/10
  • 1.3 fixed cells merge added - 2002/9/27
  • 1.2 print bug fixed - 2002/9/23
  • 1.1 scroll bug fixed - 2002/9/18
  • 1.0 first release - 2002/9/15

(Note that users of the Grid control are bound by Chris' copyright requirements detailed on his web page.)

License

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

Huang Wei

Web Developer

China China

Member

He got Master degree of Theory and Application of Automatic Control from Tsinghua university(Beijing,China) in 1997,from then on he has been working for Tsinghua TongFang Software Co.Ltd,Beijing China.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralRe: Problem deleting rows - FIXED! Pinmemberandrewtruckle3:01 9 Jun '06  
GeneralAutoSizeColumn problem Pinmemberandrewtruckle21:04 24 May '06  
GeneralClicking on a merged cell and moving by keyboard to merged cell Pinmemberandrewtruckle21:49 23 May '06  
GeneralRe: Clicking on a merged cell and moving by keyboard to merged cell - Solution Pinmemberandrewtruckle23:24 23 May '06  
GeneralAdd MergeCell function with CGridCtrl2.25 PinmemberMajorVon22:09 11 Aug '05  
GeneralRe: Add MergeCell function with CGridCtrl2.25 Pinmemberandrew.truckle@atkinsglobal.com0:42 19 Sep '05  
Questionautosize merged cells? Pinmembermarkoot10:19 28 Jul '05  
Hi,
If i have text in cell (1,1) and i merged cells (1,1,1,7)
and when my text is too big for cell (1,1) AutoSize function resizes my (1,1) cells, but my text isn't too big for merged cells (1,1,1,7) (i mean there is a lot of place in whole row which is merged as one cells)$;
Better for me would be AutoSize also for merge cells.
 
Hmm, i will try to draw mky problem;
I have :
|______|_____|
|MyBigText___| <-this one is merged
 
After using AutoSize i have
 
|_________|_____|
|MyBigText______|
Column number 0 shouldn't be resized
 
// ___ means spacebar
 
Somebody helps me?
Thanks a lot.
 
//I hope i will be understood
 
df
GeneralI fixed the bug that it can't show the last line of grid. Pinmembervictor_zhao22:07 10 Jul '05  
Generalcannot downlaod the demo Pinmembermanjuvk19:35 9 Apr '05  
GeneralVirtual Mode PinmemberTimPreuss2:32 5 Jan '05  
Generalword wrapping Pinmemberandrew.truckle@atkinsglobal.com3:47 7 Oct '04  
GeneralRe: word wrapping PinmemberIce13745:45 21 May '06  
GeneralRe: word wrapping Pinmemberandrewtruckle8:14 21 May '06  
QuestionCan I have Tree Cells and merged cells on the same grid PinsussRafael Melo9:45 13 Sep '04  
QuestionHow to print MFC GridControl ? Pinmemberlzs17:10 14 Aug '04  
GeneralI can't download the source files. PinsussTommyChoi18:59 18 Jun '04  
General2.25version PinmemberDarter1:24 27 Apr '04  
GeneralRe: 2.25version Pinmemberigrzalja4:33 30 Aug '04  
GeneralRe: 2.25version Pinmemberandrew.truckle@atkinsglobal.com0:46 19 Sep '05  
GeneralRe: 2.25version Pinmemberqz_yc_kj3:37 13 Nov '05  
GeneralRe: 2.25version Pinmemberhomerhuang17:42 21 Feb '06  
GeneralRe: 2.25version Pinmembermikewolfli22:32 25 Apr '06  
GeneralProblem with Scrolling PinmemberJIJESH.G1:16 1 Mar '04  
GeneralRe: Problem with Scrolling PinsussKiato L.1:49 6 Aug '04  
GeneralProblem with printing merging cells in fixed columns Pinmemberwlegierski1:29 2 Dec '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120529.1 | Last Updated 30 Dec 2002
Article Copyright 2002 by Huang Wei
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid