Association Grid Control

Recently, I had to try to find a control that would show associations between several items. I've looked through the CodeGuru Web site 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.

Features:

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"

protected:
	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.SetRedraw(FALSE);

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

m_Grid.AddRow("Mike", FALSE);
m_Grid.AddRow("Cathy", TRUE); //TRUE = recalc layout

m_Grid.SetRedraw(TRUE);

Downloads

Download source - 13 Kb
Download demo project - 72 Kb


Comments

  • Wanted: Association grid control as ocx?

    Posted by martyn_priestnall on 05/20/2004 10:04am

    I really like this grid and really would very useful
    me to have it in ocx format so I could plug it into a
    vb project i'm working on. But I'm no VC++ programmer,
    and it's somewhat daunting a prospect to convert this myself. I looked and i didn't like what I saw...
    Is there any C++ programmer out there would be so kind
    as to produce an ocx of this control?
    
    Thought it's worth asking...you never know!
    
    Cheers anyway
    Martyn

    Reply
  • I need graphic like grant diagram

    Posted by Legacy on 02/17/2003 12:00am

    Originally posted by: demba

    Hi,
    
    

    First of all thanks for the work.

    I have graphic like grant diagram (Task,duration Month). Where can i take it. Like MSProject diagram
    Thanks to all who reply.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds