Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A fast and lightweight cell control

0.00/5 (No votes)
11 Mar 2008 1  
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

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