Click here to Skip to main content
15,169,508 members
Articles / Desktop Programming / WTL
Posted 29 Jun 2006


81 bookmarked

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.

Sample Image - MyCell.PNG


A fast and lightweight cell control which can be easily extended was my requirement. There are some grid controls derived or subclassed with CListCtrl already available. CListCtrl is great and very fast, but still has some limitations, such as it has no row header, and merging cells is not easy to support. Last month, I decided to write my own grid control, and wanted to share my source code with others here, because some of my knowledge is learned from CodeProject. Thanks to Chris Maunder for his MFC Grid control 2.25; I learned a lot from it. And, thanks Vladislav Gelfer for his RgnLight class which is very useful for clipping.


  • ATL 7.0/7.1
  • WTL 7.5/8.0


Use the APIs GetRegionData and ScrollWindow to reduce repainting is the main idea for speeding up the painting of the grid. Only those cells with invalid states need to be re-drawn, so there is no need to re-draw the valid cells. When we do it this way, there is no flicker, even if do not use memdc, and the painting is very fast.


Image 2


  1. Like Excel, a Workbook manages many Worksheets.
  2. Merge and unmerge cells.
  3. Freeze.
  4. Import/export XML (Excel format).
  5. Styles (font, border, alignment, fill, ...).
  6. Default/custom cell symbol.
  7. Default/custom cell editor.
  8. Using light weight COM object makes easily extendible.
  9. Use real/virtual mode to manage data.
  10. Drag active selection.
  11. Single selection or multi-selection support.


  • 17 July, 2006 - Supports editing cells.
  • 17 July, 2006 - Supports merging cells.
  • 11 July, 2006 - Auto scroll in selection model when mouse is out of the grid client area.


Any comments or questions can be sent to


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions

Generalgood article Pin
qusuo4-Mar-14 21:37
Memberqusuo4-Mar-14 21:37 
General很好的控件,必须要顶! Pin
firespout27-Sep-13 3:42
Memberfirespout27-Sep-13 3:42 
QuestionVC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory Pin
Paul Soloveychik31-Mar-11 8:39
MemberPaul Soloveychik31-Mar-11 8:39 
AnswerRe: VC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory Pin
Richard GILL3-Apr-12 2:43
MemberRichard GILL3-Apr-12 2:43 
GeneralThank´s Pin
Joao Araujo30-Nov-09 12:37
MemberJoao Araujo30-Nov-09 12:37 
QuestionIt doesn't allow entering some text into CELL? Pin
michael. zhao12-Mar-08 17:47
Membermichael. zhao12-Mar-08 17:47 
I can copy and paste some text into one cell but entering directly doesn't work...
AnswerRe: It doesn't allow entering some text into CELL? Pin
xueming.yan12-Mar-08 20:40
Memberxueming.yan12-Mar-08 20:40 
Generalusing c++ MFC vc6 Pin
ori kovacsi11-Jul-06 19:46
Memberori kovacsi11-Jul-06 19:46 
GeneralRe: using c++ MFC vc6 Pin
xueming.yan11-Jul-06 22:32
Memberxueming.yan11-Jul-06 22:32 
GeneralNice: some suggestions Pin
Jerry Evans1-Jul-06 2:40
MemberJerry Evans1-Jul-06 2:40 
GeneralRe: Nice: some suggestions Pin
xueming.yan2-Jul-06 16:57
Memberxueming.yan2-Jul-06 16:57 
GeneralRe: Nice: some suggestions Pin
xueming.yan3-Jul-06 16:37
Memberxueming.yan3-Jul-06 16:37 
GeneralErm... Pin
Jonathan [Darka]29-Jun-06 23:55
professionalJonathan [Darka]29-Jun-06 23:55 
GeneralRe: Erm... Pin
xueming.yan30-Jun-06 0:59
Memberxueming.yan30-Jun-06 0:59 

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.