Click here to Skip to main content
Click here to Skip to main content

Adding "Merge cells" support to the MFC GridControl

, 29 Dec 2002
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Huang Wei
Web Developer
China China
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.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberFaint789020-Apr-13 22:01 
Questionset color of tool bar button text PinmemberUday P.Singh16-Feb-12 1:57 
GeneralDrawing issue in merging cell PinmemberMember 304756327-May-11 3:19 
GeneralSetItemBkColour function will make grid line disappear Pinmemberzhuguo30-Jun-09 1:06 
GeneralMerged cell disapears while sorting PinmemberTanmaySathe17-Feb-09 18:14 
QuestionHow can i generate a DLL and an OCX file for this code in your attachment? Pinmemberpraveen_sap25-Jan-09 11:55 
General[Message Removed] Pinmemberimmetoz6-Oct-08 7:55 
Questionunable to download the attachment file PinmemberG Haranadh30-Jul-08 2:48 
Generalprint probs Pinmemberzhkingsmac7-Jul-08 16:35 
Generalin virtual mode, merge cells function doesn't work properly PinmemberMember 46478006-Mar-08 21:02 
QuestionPrintCell is wrong Pinmemberandrewtruckle5-Aug-07 20:06 
AnswerRe: PrintCell is wrong Pinmemberandrewtruckle5-Aug-07 22:01 
QuestionHow to save the merged grid infomation?? Pinmemberhhuwangzhp198026-Jun-07 18:01 
GeneralAdding a BITMAP Pinmemberhodeck~10-Sep-06 20:08 
QuestionHas anyone got this working properly in v2.26 ? Pinmemberjfougero4-Sep-06 17:05 
AnswerRe: Has anyone got this working properly in v2.26 ? Pinmemberhamo200827-Nov-06 20:05 
AnswerRe: Has anyone got this working properly in v2.26 ? PinmemberMember 382164026-Jun-08 23:56 
I complete this.
compare file with the UltraEdit's
then modify the file of 2.26 version
 
It compile successful and run successful
 
If you want to get the code, Then Mail Me,please;
My Mail is geoh#vip.qq.com (replace # to @)
the mail's subject must be MFC Grid Control with Merge!
Thanks,My English is bad,Sorry
Generalbug: Merge the merged cells --fixed Pinmemberhamo200826-Jul-06 5:40 
GeneralRe: bug: Merge the merged cells --fixed Pinmembercuiting9-Dec-12 22:18 
GeneralProblem deleting rows Pinmemberandrewtruckle8-Jun-06 1:39 
GeneralRe: Problem deleting rows Pinmemberandrewtruckle8-Jun-06 3:53 
GeneralRe: Problem deleting rows - FIXED! Pinmemberandrewtruckle9-Jun-06 3:01 
GeneralAutoSizeColumn problem Pinmemberandrewtruckle24-May-06 21:04 
GeneralClicking on a merged cell and moving by keyboard to merged cell Pinmemberandrewtruckle23-May-06 21:49 
GeneralRe: Clicking on a merged cell and moving by keyboard to merged cell - Solution Pinmemberandrewtruckle23-May-06 23:24 
GeneralAdd MergeCell function with CGridCtrl2.25 PinmemberMajorVon11-Aug-05 22:09 
GeneralRe: Add MergeCell function with CGridCtrl2.25 Pinmemberandrew.truckle@atkinsglobal.com19-Sep-05 0:42 
Questionautosize merged cells? Pinmembermarkoot28-Jul-05 10:19 
GeneralI fixed the bug that it can't show the last line of grid. Pinmembervictor_zhao10-Jul-05 22:07 
Generalcannot downlaod the demo Pinmembermanjuvk9-Apr-05 19:35 
GeneralVirtual Mode PinmemberTimPreuss5-Jan-05 2:32 
Generalword wrapping Pinmemberandrew.truckle@atkinsglobal.com7-Oct-04 3:47 
GeneralRe: word wrapping PinmemberIce137421-May-06 5:45 
GeneralRe: word wrapping Pinmemberandrewtruckle21-May-06 8:14 
QuestionCan I have Tree Cells and merged cells on the same grid PinsussRafael Melo13-Sep-04 9:45 
QuestionHow to print MFC GridControl ? Pinmemberlzs14-Aug-04 17:10 
GeneralI can't download the source files. PinsussTommyChoi18-Jun-04 18:59 
General2.25version PinmemberDarter27-Apr-04 1:24 
GeneralRe: 2.25version Pinmemberigrzalja30-Aug-04 4:33 
GeneralRe: 2.25version Pinmemberandrew.truckle@atkinsglobal.com19-Sep-05 0:46 
GeneralRe: 2.25version Pinmemberqz_yc_kj13-Nov-05 3:37 
GeneralRe: 2.25version Pinmemberhomerhuang21-Feb-06 17:42 
GeneralRe: 2.25version Pinmembermikewolfli25-Apr-06 22:32 
GeneralProblem with Scrolling PinmemberJIJESH.G1-Mar-04 1:16 
GeneralRe: Problem with Scrolling PinsussKiato L.6-Aug-04 1:49 
GeneralProblem with printing merging cells in fixed columns Pinmemberwlegierski2-Dec-03 1:29 
GeneralRe: Problem with printing merging cells in fixed columns Pinmemberyuhonggang27-Nov-04 5:02 
GeneralRe: Problem with printing merging cells in fixed columns PinmemberCui Sheng14-Feb-05 22:15 
GeneralProblem when changing cell colors PinmemberJAlcant12327-Oct-03 12:30 
GeneralFix to problem not showing grid when changing cell colors Pinmembershawkins9-Jan-04 7:48 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 30 Dec 2002
Article Copyright 2002 by Huang Wei
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid