5,659,906 members and growing! (17,452 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Grid Control     Intermediate

Adding "Merge cells" support to the MFC GridControl

By Huang Wei

Adding "Merge cells" support to the MFC GridControl.
VC6, VC7, C++Windows, Win2K, WinXP, MFC, VS.NET2002, VS6, Visual Studio, Dev

Posted: 14 Sep 2002
Updated: 29 Dec 2002
Views: 113,721
Bookmarked: 55 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
35 votes for this Article.
Popularity: 6.97 Rating: 4.52 out of 5
3 votes, 12.5%
1
0 votes, 0.0%
2
2 votes, 8.3%
3
1 vote, 4.2%
4
18 votes, 75.0%
5

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


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.
Occupation: Web Developer
Location: China China

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 96 (Total in Forum: 96) (Refresh)FirstPrevNext
General[Message Removed]memberimmetoz8:55 6 Oct '08  
Questionunable to download the attachment filememberG Haranadh3:48 30 Jul '08  
Generalprint probsmemberzhkingsmac17:35 7 Jul '08  
Generalin virtual mode, merge cells function doesn't work properlymemberMember 464780022:02 6 Mar '08  
QuestionPrintCell is wrongmemberandrewtruckle21:06 5 Aug '07  
AnswerRe: PrintCell is wrongmemberandrewtruckle23:01 5 Aug '07  
GeneralHow to save the merged grid infomation??memberhhuwangzhp198019:01 26 Jun '07  
GeneralAdding a BITMAPmemberhodeck~21:08 10 Sep '06  
QuestionHas anyone got this working properly in v2.26 ?memberjfougero18:05 4 Sep '06  
AnswerRe: Has anyone got this working properly in v2.26 ?memberhamo200821:05 27 Nov '06  
AnswerRe: Has anyone got this working properly in v2.26 ?memberMember 38216400:56 27 Jun '08  
Generalbug: Merge the merged cells --fixedmemberhamo20086:40 26 Jul '06  
GeneralProblem deleting rowsmemberandrewtruckle2:39 8 Jun '06  
GeneralRe: Problem deleting rowsmemberandrewtruckle4:53 8 Jun '06  
GeneralRe: Problem deleting rows - FIXED!memberandrewtruckle4:01 9 Jun '06  
GeneralAutoSizeColumn problemmemberandrewtruckle22:04 24 May '06  
GeneralClicking on a merged cell and moving by keyboard to merged cellmemberandrewtruckle22:49 23 May '06  
GeneralRe: Clicking on a merged cell and moving by keyboard to merged cell - Solutionmemberandrewtruckle0:24 24 May '06  
GeneralAdd MergeCell function with CGridCtrl2.25memberMajorVon23:09 11 Aug '05  
GeneralRe: Add MergeCell function with CGridCtrl2.25memberandrew.truckle@atkinsglobal.com1:42 19 Sep '05  
Generalautosize merged cells?membermarkoot11:19 28 Jul '05  
GeneralI fixed the bug that it can't show the last line of grid.membervictor_zhao23:07 10 Jul '05  
Generalcannot downlaod the demomembermanjuvk20:35 9 Apr '05  
GeneralVirtual ModememberTimPreuss3:32 5 Jan '05  
Generalword wrappingmemberandrew.truckle@atkinsglobal.com4:47 7 Oct '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Dec 2002
Editor: Smitha Vijayan
Copyright 2002 by Huang Wei
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project