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
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
Features
- Like Excel, a Workbook manages many Worksheets.
- Merge and unmerge cells.
- Freeze.
- Import/export XML (Excel format).
- Styles (font, border, alignment, fill, ...).
- Default/custom cell symbol.
- Default/custom cell editor.
- Using light weight COM object makes easily extendible.
- Use real/virtual mode to manage data.
- Drag active selection.
- 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.