Click here to Skip to main content
13,096,798 members (97,010 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 14 Nov 2000

Grid Control Showing Association

, 14 Nov 2000
Rate this:
Please Sign up or sign in to vote.
Grid control with vertical column headers.


Recently, I had to try to find a control that would show associations between several items. I've looked through the CodeGuru website to find out such a control. Unfortunately, I did not find any control that met my expectations. In fact, I found a control that was quite similar, written by Chris Copenhaver. The problem was that I needed a more flexible control. I know I could have tried to extend the basic functionalities of his control, but instead of modifying someone else's code, I've decided to code it from scratch.

Basically, I am posting two classes here. The first one is the control itself (CDualGridCtrl) and the second one is a custom view wrapping my grid control (CDualGridView). Thanks to Charles Calvert for his nice article about creating a custom view of our own control.


You can change the font name and font size of the row names, the column names and the squares. Furthermore, you can set the text color of each square. Each square supports two modes: Symbol and Text. In symbol mode, you can set any symbol provided by the WingDings font. You can also change the background color of the control. The control sends two notification messages: AFTER_DRAW_TOPLEFT and SQUARE_CLICK.

AFTER_DRAW_TOPLEFT is called each time the control is drawn, if the top left corner is at least partly visible. This notification message allows you to draw something in the left corner if you wish to.

SQUARE_CLICK is called whenever the user left clicked on a square in the control.

For the implementation of these two notifications, look at the demo code.

How to use in a SDI or MDI applicaion

Step 1: Derive a custom class from CView

This is easily done with the Class Wizard. Simply click on the "Add" button and choose "New class...". Select CView as the base class and enter a name for your derived class.

Step 2: Derive your new class from CDualGridView instead of CView

This means you have to (using Search/Replace) replace all instances of CView with CDualGridView in the .cpp file.

Step 3: Override the OnInitialUpdate function in your new view

In the body of that function, fill in the control.

How to use in a dialog based applicaion

Step 1: Insert a static control in your dialog resource

Do not associate any variable with it.

Step 2: Insert a CDualGridCtrl variable in your dialog header file.

#include "DualGridCtrl.h"

    CDualGridCtrl m_Grid;

Step 3: Create the control in the OnInitDialog function.

if ( !m_Grid.CreateFromStatic(IDC_STATIC_CHART, "Grid Ctrl", this) )
    TRACE("Failed to create the grid control...\n");

The function CreateFromStatic was created by Paul DiLascia. For more details, you can read his article on Microsoft MSJ web site.

Step 4: Fill the control

m_Grid.AddColumn("Tennis", FALSE);
m_Grid.AddColumn("Hiking", FALSE);
m_Grid.AddRow("Mike", FALSE);

// TRUE means that you want the
//control to recalculate its layout.
m_Grid.AddRow("Cathy", TRUE);


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


About the Author

Daniel Larocque
Web Developer
Canada Canada
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralWant to extend this application Pin
kinju27-Oct-04 22:28
susskinju27-Oct-04 22:28 
GeneralWanted by VB programmer: An OCX version... Pin
priestnall20-May-04 4:11
memberpriestnall20-May-04 4:11 
GeneralModification Pin
wb11-May-04 5:14
memberwb11-May-04 5:14 
GeneralLooks good but not editable Pin
noemailpls61230-Nov-03 7:39
sussnoemailpls61230-Nov-03 7:39 
GeneralVery cool UI Pin
Hockey7-Aug-02 15:15
memberHockey7-Aug-02 15:15 
GeneralExcellent grid, but.... Pin
Bassam Abdul-Baki30-Jun-02 13:03
memberBassam Abdul-Baki30-Jun-02 13:03 
GeneralNice UI Pin
Norm Almond11-Dec-00 1:13
memberNorm Almond11-Dec-00 1:13 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 15 Nov 2000
Article Copyright 2000 by Daniel Larocque
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid