<< Return to Main Index

< Return to Class Index

class CGXControl

The CGXControl class is an abstract base class.  CGXControl establishes a default grid-to-control interface that derived grid control classes must implement.  If deriving from CGXControl only, controls can be entirely implemented by the derived class by overriding the Draw method and some other virtual methods.

CGXControl can also be created in conjunction with existing MFC control classes to implement a standard MFC control derivative.  The resulting MFC control derivative derives its message map from the MFC inheritance and its grid properties from the CGXControl inheritance.  For example, classes CGXEditControl, CGXComboBoxWnd and CGXListBox are MFC control derivatives that use this approach.

A control can have several CGXChild objects. A good example for using child objects is CGXSpinEdit, which has up- and down-arrow buttons at the right side of the cell.

When you want to use CGXControl-derived classes as cells, you need to register the control in the grid with a numeric identifier at runtime. The following steps are necessary:

1. You need to add a string resource:


// Your .RC - file:

      IDS_CTRL_BITMAP        "Welcome bitmap"

2. In OnInitialUpdate, you should pass a new instance of the object together with the string resource id to RegisterControl.

void CGridSampleView::OnInitialUpdate( )

      new CGXBitmapButton(this, IDB_WELCOME));

3. Now you can apply the control to any cell in the grid with CGXStyle::SetControl.

// Display the welcome bitmap
SetStyleRange(CGXRange( 3, 2 ), CGXStyle( )
   .SetControl( IDS_CTRL_BITMAP ));

When you derive a class from CGXControl, you should also add a GRID_DECLARE_CONTROL / GRID_IMPLEMENT_CONTROL macro pair for the class.

And if you did derive from a CWnd class, you should also add a GRID_DECLARE_DYNAMIC / IMPLEMENT_DYNAMIC macro pair for the class.

#include <gxall.h>

See Also

CGXStyle CGXEditControl CGXComboBoxWnd CGXListBox CGXGridCore::RegisterControl CGXStyle::SetControl


Class Members