Objective Grid : PART I User’s Guide : Chapter 5 Using Objective Grid : Events
Events
 
Keyboard Events
Microsoft Windows sends keyboard events to the active window. MFC will call the message method OnKeyDown() for the active window. Objective Grid will call the method CGXGridCore::ProcessKeys().
ProcessKeys() is called both from the current cell control and the grid itself, depending on active state of the current cell. ProcessKeys() needs to know which window is calling it. For this reason, the calling window passes the this pointer to ProcessKeys().
If you want to process keyboard events, you should override ProcessKeys() in a derived grid class. The return value of ProcessKeys() specifies if the event has been processed.
The following example illustrates how to override ProcessKeys() to process the F1 and TAB keys. If the user presses TAB at the bottom-right cell, a new row will be added to the table.
It is important to realize that ProcessKeys() is called from both OnKeyDown and OnKeyUp message handlers. You should keep this in mind when overriding ProcessKeys(), as it may be necessary to distinguish between WM_KEYDOWN and WM_KEYUP messages.
 
BOOL CGSampleView::ProcessKeys(CWnd* pSender, UINT nMessage,
UINT nChar, UINT nRepCnt, UINT flags)
{
// check if user pressed <CTRL>-Key
BOOL bCtl = GetKeyState(VK_CONTROL) & 0x8000;
 
// check if user pressed <SHIFT>-Key
BOOL bShift = GetKeyState(VK_SHIFT) & 0x8000;
 
if (nMessage == WM_KEYDOWN)
{
switch (nChar)
{
case VK_HELP: // user pressed <F1>-Key
// display a message box with help
if (bShift)
{
MessageBox("Help!");
return TRUE;
}
case VK_TAB: // user pressed <TAB>-Key
{
ROWCOL nRow = 1, nCol = 1;
GetCurrentCell(nRow, nCol);
if (!bShift)
{
// Jump to the right cell
if (nCol < GetColCount())
MoveCurrentCell(GX_RIGHT);
else if (nRow < GetRowCount())
{
// if current cell is at last column,
// move down a row and to the first column.
if (MoveCurrentCell(GX_MOSTLEFT))
MoveCurrentCell(GX_DOWN);
}
else
{
// if current cell is at last row,
// add a new row
SetRowCount(GetRowCount()+1);
 
// move to the first column in the new row
if (MoveCurrentCell(GX_MOSTLEFT))
MoveCurrentCell(GX_DOWN);
}
}
else
{
// Jump to the left cell or move up a row
if (nCol > 1)
MoveCurrentCell(GX_LEFT);
else if (nRow > 1)
{
if (MoveCurrentCell(GX_MOSTRIGHT))
MoveCurrentCell(GX_UP);
}
else
{
MoveCurrentCell(GX_BOTTOMRIGHT);
}
}
return TRUE;
}
}
}
 
// call base class version
return CGXGridView::ProcessKeys(pSender,nMessage,nChar,nRepCnt,flags);
}
Keyboard Shortcuts
Table 4 lists keyboard shortcuts available in Objective Grid.
Table 4 – Keyboard shortcuts 
Shortcut
Action
CTRL+Z
Undo
CTRL+R
Redo
CTRL+C
Copy
CTRL+V
Paste
CTRL+X
Cut