Click here to Skip to main content
Licence 
First Posted 14 Sep 2002
Views 155,994
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
Questionset color of tool bar button text PinmemberUday P.Singh1:57 16 Feb '12  
GeneralDrawing issue in merging cell PinmemberMember 30475633:19 27 May '11  
GeneralSetItemBkColour function will make grid line disappear Pinmemberzhuguo1:06 30 Jun '09  
GeneralMerged cell disapears while sorting PinmemberTanmaySathe18:14 17 Feb '09  
QuestionHow can i generate a DLL and an OCX file for this code in your attachment? Pinmemberpraveen_sap11:55 25 Jan '09  
General[Message Removed] Pinmemberimmetoz7:55 6 Oct '08  
Questionunable to download the attachment file PinmemberG Haranadh2:48 30 Jul '08  
Generalprint probs Pinmemberzhkingsmac16:35 7 Jul '08  
Generalin virtual mode, merge cells function doesn't work properly PinmemberMember 464780021:02 6 Mar '08  
QuestionPrintCell is wrong Pinmemberandrewtruckle20:06 5 Aug '07  
AnswerRe: PrintCell is wrong Pinmemberandrewtruckle22:01 5 Aug '07  
QuestionHow to save the merged grid infomation?? Pinmemberhhuwangzhp198018:01 26 Jun '07  
GeneralAdding a BITMAP Pinmemberhodeck~20:08 10 Sep '06  
QuestionHas anyone got this working properly in v2.26 ? Pinmemberjfougero17:05 4 Sep '06  
AnswerRe: Has anyone got this working properly in v2.26 ? Pinmemberhamo200820:05 27 Nov '06  
AnswerRe: Has anyone got this working properly in v2.26 ? PinmemberMember 382164023:56 26 Jun '08  
Generalbug: Merge the merged cells --fixed Pinmemberhamo20085:40 26 Jul '06  
GeneralProblem deleting rows Pinmemberandrewtruckle1:39 8 Jun '06  
GeneralRe: Problem deleting rows Pinmemberandrewtruckle3:53 8 Jun '06  
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  
Can't the same instructions be followed in 2.25?
 
Andrew

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
Web02 | 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