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

A fast and lightweight cell control

, 11 Mar 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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.



  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 Pinmemberqusuo4-Mar-14 21:37 
General很好的控件,必须要顶! Pinmemberfirespout27-Sep-13 3:42 
QuestionVC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory PinmemberPaul Soloveychik31-Mar-11 8:39 
AnswerRe: VC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory PinmemberRichard GILL3-Apr-12 2:43 
GeneralThank´s PinmemberJoao Araujo30-Nov-09 12:37 
QuestionIt doesn't allow entering some text into CELL? Pinmembermichael. zhao12-Mar-08 17:47 
AnswerRe: It doesn't allow entering some text into CELL? Pinmemberxueming.yan12-Mar-08 20:40 
you should set celltype as ECT_TEXT,there are some methods,such as put_ColType(ECT_TEXT) for some columns or SetCellType(CCell cell,ECellType cellType) for some cells,or Style_SetRowStyle from some rows or Style_SetTableStyle for whole table.
You also can create your own custom editor for edit.Cell editor is a COM object which implements ICellEditor interface.then you should call CellTypeFactory::SetEditor for your custom celltype.
There are two editors CheckBoxEditor and TextEditor.
TextEditor assioate with : ECT_TEXT,
CheckBoxEditor :ECT_CHECKBOX

later i will post some examples.
Generalusing c++ MFC vc6 Pinmemberori kovacsi11-Jul-06 19:46 
GeneralRe: using c++ MFC vc6 Pinmemberxueming.yan11-Jul-06 22:32 
GeneralNice: some suggestions PinmemberJerry Evans1-Jul-06 2:40 
GeneralRe: Nice: some suggestions Pinmemberxueming.yan2-Jul-06 16:57 
GeneralRe: Nice: some suggestions Pinmemberxueming.yan3-Jul-06 16:37 
GeneralErm... PinmemberDarka29-Jun-06 23:55 
GeneralRe: Erm... Pinmemberxueming.yan30-Jun-06 0:59 

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 | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 12 Mar 2008
Article Copyright 2006 by xueming.yan
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid