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

The Grid Control

By , , , , 5 Jun 2000
 

Introduction

After pushing the CListCtrl to its limits in trying to display and edit tabulated data I decided what was really needed was a dedicated grid control. I started writing my own grid control from scratch but decided to save time by modifying Joe Willcoxson's free WorldCom grid control. I tore apert his code and rebuilt it from the ground up in order to get it to do all the things I needed. The code has gone through so many modifications that I'm not sure if there is even a single original line of code. In any case Joe's code was a great framework on which to build.

Since the initial release at the beginning of 1998 there have been many, many versions of the grid - some better than others. There have also been ports to CE, an ATL version, and extensions that include a tree-list control.

The list of all those who have contributed and provided fixes, bug reports and suggestions is too huge to mention - thanks everyone!

The Grid Control articles and projects

The Grid

MFC Grid control - Chris Maunder
A fully featured grid control for displaying tabular data that is derived from CWnd

Plug-in cell types

Tree control and Buttons for MFC Grid control - Ken Bertelson
A set of classes derived from CGridCtrl that embed a tree control, button controls, and virtual cells within the grid

Using comboboxes in the MFC Grid Control - Chris Maunder
Explains how to use comboboxes to edit cells in the MFC Grid Control

Adding Hyperlink support to the MFC Grid Control - Fred Ackers and Chris Maunder
A new class that adds hyperlink support to the MFC Grid Control

Using the Grid

Using the Grid Control in a Doc/View framework - Chris Maunder
A simple tutorial that demonstrates how to use the grid control in a doc/view application.

ActiveX version

ATL Grid control - Mario Zucca
A grid control for displaying tabular data, based on Chris Maunder's grid control

License

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

About the Authors

Chris Maunder
Founder CodeProject
Canada Canada
Member
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.
 
His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.
 
He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.
 
Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

Ken Bertelson
United States United States
Member
No Biography provided

Mario Zucca
Web Developer
Italy Italy
Member
No Biography provided

Fred Ackers
Web Developer
United States United States
Member
Programming using MFC and ATL for almost 12 years now. Currently studying Operating System implementation as well as Image processing. Previously worked on DSP and the use of FFT for audio application. Programmed using ADO, ODBC, ATL, COM, MFC for shell interfacing, databasing tasks, Internet items, and customization programs.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberMarco Bertschi21 Mar '13 - 0:23 
Thumbs Up | :thumbsup:
GeneralMy vote of 5membersariqkhan20 Nov '12 - 16:57 
excellent
QuestionBug fix for frozen columnsmemberDavid Pritchard13 Sep '11 - 4:58 
Hi all,
 
Not sure if someone already mentioned this (or if it's fixed in a more recent version of the code than the one I have), but there's a bug in the painting of vertical column lines when the first non-fixed column is hidden (width 0).
 
In CGridCtrl::OnDraw(CDC* pDC), in the section that draws the lines, look for:
 
	 // draw vertical lines (drawn at ends of cells)
	 if (m_nGridLines == GVL_BOTH || m_nGridLines == GVL_VERT)
	 {
		.
		.
		.
		// LUC - frozen col stuff
		if(col == (m_nFixedCols + m_nFreezedCols))
 
 
Change this last line to:
 
		// DP 13/09/2011: Fix - this fails when the first non-fixed column is invisible - 
		// we skip past it in the previous line, and the column never gets shifted to  
		// minVisibleCol
		if(col >= (m_nFixedCols + m_nFreezedCols) && col < minVisibleCol)
 
- Pfft. Coddled kids. In my day, we used to telnet to port 80, then render the page with pencil and paper-- and that's the way we liked it!
- Pshaw! Youngster. Your UID barely fits inside 16 bits. In _my_ day we had to whistle the 1's and 0's through an acoustic coupler!
 
Tools that support "all of UTF-8 as long as it starts with ASCII" and tools that cannot handle these three [BOM] bytes at all are not really supporting UTF-8.
- Michael Kaplan

AnswerRe: Bug fix for frozen columnsmemberDavid Pritchard13 Sep '11 - 4:59 
Sorry, forgot to mention that the error happens when you scroll to the right. That's when the painting gets screwed up.
- Pfft. Coddled kids. In my day, we used to telnet to port 80, then render the page with pencil and paper-- and that's the way we liked it!
- Pshaw! Youngster. Your UID barely fits inside 16 bits. In _my_ day we had to whistle the 1's and 0's through an acoustic coupler!
 
Tools that support "all of UTF-8 as long as it starts with ASCII" and tools that cannot handle these three [BOM] bytes at all are not really supporting UTF-8.
- Michael Kaplan

QuestionIs any full row selection api?memberERLN10 Aug '11 - 1:37 
I have grid ctrl. Is any api for full row selection (list listview style )
GeneralNumbers onlymemberMember 2608808 May '11 - 7:44 
I may be blind.. looking at code for too long. But, how do I limit data entry to just numbers (no alpha, etc)? And how about just limiting to a dollar value? I.e. 10.45?
QuestionCan't create MFCGridCtrl in the DLL dialogmembers9510301025 May '10 - 20:54 
Hello,
 
I have some problem with DLL based MFCGridCtrl.
 
There are two projects in my solution. (visual studio 2008)
one is Dialog based EXE, other is MFC Extend DLL .
 
in DLL project, I added a dialog and put a custom control to make Grid.
When I call this dll dialog from EXE project,there will be some error.
 
I have found many people have same problem in this case.
 
does anynone have some sample code ?
 
thanks.
QuestionCFormView-based application doesn't catch the WM_NOTIFY messagesmemberhjfyyy9 Apr '10 - 4:33 
Hello.
First I insert a Grid Control into my form view, but i need to response the OnEndEdit messages in form view class. But i doesn't work. So any suggestions?
Questionany vb.net version?memberfira211124 Feb '08 - 15:41 
i want to know is there any vb.net version for this program?
 
fira

GeneralFlikerring in Gridmemberkansagous25 Dec '07 - 19:21 
Message:- Any one can tell me how to remove flickering occurring in my grid view.
 
Problem is that I am fetching some data and refreshing it directly into my grid but when it populate data then, due to refreshing it, it is flickering in the grid view.
Rose | [Rose]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 6 Jun 2000
Article Copyright 2000 by Chris Maunder, Ken Bertelson, Mario Zucca, Fred Ackers
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid