Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / WTL
Article

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 90.9K   4.5K   81   14
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.

Sample Image - MyCell.PNG

Introduction

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.

Requirements

  • ATL 7.0/7.1
  • WTL 7.5/8.0

Emphasis

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.

Infrastructure

Image 2

Features

  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.

History

  • 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.

Conclusion

Any comments or questions can be sent to xueming.yan@gmail.com.

License

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


Written By
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 20:37
qusuo4-Mar-14 20:37 
General很好的控件,必须要顶! Pin
firespout27-Sep-13 2:42
firespout27-Sep-13 2:42 
用了你这个控件,谢谢!

本来想在视图中直接嵌入Excel,花了几天时间研究,后来虽然嵌进去了,但还有很多问题。例如不知如何隐藏上方的功能区,如何限制用户操作,如何接收事件等等,最后不得不放弃。

后来找到了myCell控件,外观高仿Excel,完全能够满足我的显示需求,太好了。
花了一天时间,编译出了dll,成功嵌入到了我的MFC视图中,这其中也修改了一些代码(项目在VS2008下无法直接编译)。
现在刚刚显示出来,后边还要接收事件,不知道MFC的视图有没有问题,明天再研究一下。

再次感谢。
QuestionVC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory Pin
Paul Soloveychik31-Mar-11 7:39
Paul Soloveychik31-Mar-11 7:39 
AnswerRe: VC++2010:fatal error C1083: Cannot open include file: 'atlapp.h': No such file or directory Pin
Richard GILL3-Apr-12 1:43
Richard GILL3-Apr-12 1:43 
GeneralThank´s Pin
Joao Araujo30-Nov-09 11:37
Joao Araujo30-Nov-09 11:37 
QuestionIt doesn't allow entering some text into CELL? Pin
michael. zhao12-Mar-08 16:47
michael. zhao12-Mar-08 16:47 
AnswerRe: It doesn't allow entering some text into CELL? Pin
xueming.yan12-Mar-08 19:40
xueming.yan12-Mar-08 19:40 
Generalusing c++ MFC vc6 Pin
ori kovacsi11-Jul-06 18:46
ori kovacsi11-Jul-06 18:46 
GeneralRe: using c++ MFC vc6 Pin
xueming.yan11-Jul-06 21:32
xueming.yan11-Jul-06 21:32 
GeneralNice: some suggestions Pin
Jerry Evans1-Jul-06 1:40
Jerry Evans1-Jul-06 1:40 
GeneralRe: Nice: some suggestions Pin
xueming.yan2-Jul-06 15:57
xueming.yan2-Jul-06 15:57 
GeneralRe: Nice: some suggestions Pin
xueming.yan3-Jul-06 15:37
xueming.yan3-Jul-06 15:37 
GeneralErm... Pin
Jonathan [Darka]29-Jun-06 22:55
professionalJonathan [Darka]29-Jun-06 22:55 
GeneralRe: Erm... Pin
xueming.yan29-Jun-06 23:59
xueming.yan29-Jun-06 23: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.