Controls
 
Registration and Usage of Controls
You need to register new controls in the grid object (with CGXGridCore::RegisterControl) before using them as cell controls. You do this using a string resource identifier at run time. The name of the registered control will be displayed in the list box of the Controls page in the pre-built CGXStyleSheet dialog. It is not necessary to register existing Objective Grid controls. They are registered by the control factory as needed.
Follow these steps to register a control:
1. Add a string resource using Visual Studio Resource View by opening the string table in the resource file and adding your custom string resource. Your .RC - file will change accordingly:
 
STRINGTABLE DISCARDABLE
BEGIN
IDS_CTRL_BITMAP "Welcome bitmap"
END
2. In OnInitialUpdate(), pass a new instance of the object as well as the string resource ID to RegisterControl().
 
void CGridSampleView::OnInitialUpdate()
{
...
 
RegisterControl(IDS_CTRL_BITMAP,
new CGXBitmapButton(this, IDB_WELCOME));
}
NOTE >> If you are registering a control derived from an existing Objective Grid control, you should check the control factory code for creation information. Some built-in controls simply need to be constructed while others require additional steps. The control creation code is in the CGXControlFactory::CreateControl() method in gxfactry.cpp.
// Snippet from gxfactry.cpp. This code demonstrates
// the steps necessary when creating an instance of
// CGXMaskControl
case GX_IDS_CTRL_MASKEDIT:
CGXMaskControl* pEditCtrl =
new CGXMaskControl(pGrid, GX_IDS_CTRL_MASKEDIT);
pEditCtrl->CreateControl();
pControl = pEditCtrl;
break;
 
// In contrast, here's the code necessary to create an
// instance of CGXEditControl
case GX_IDS_CTRL_EDIT:
// default edit box
pControl = new CGXEditControl(pGrid, GX_IDS_CTRL_EDIT);
break;
3. Now, 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));