Objective Grid: Modifying the behavior of the tab key for a grid in a dialog

Article ID: 512
Last updated: 16 Apr, 2018
Article ID: 512
Last updated: 16 Apr, 2018
Revision: 3
Views: 2529
Posted: 19 Jan, 2001
by Meltreger B.
Updated: 16 Apr, 2018
by Meltreger B.

Problem


How can I change the behavior of the [Tab] key in a dialog? I want the [Tab] key to activate the next dialog control


Cause



Action


You should override OnGetDlgCode() (add a message map entry for WM_GETDLGCODE) and return:

return CWnd::OnGetDlgCode() | DLGC_WANTARROWS | DLGC_WANTCHARS;

And a final thing is that when an edit control has the focus, it will continue to interpret the TAB Key. A solution for this is to override ProcessKeys() and check for the TAB Key.

The following code fragments should help you. If you would like to test it immediately, you can copy them to the file dergrdlg.cpp in the sample1 application.

/////////////////////////////////////////////////////////////////
// CDerGridWnd message handlers
BOOL CDerGridWnd::ProcessKeys(CWnd* pSender, UINT nMessage, UINT nChar, UINT nRepCnt, UINT flags)
{
if (pSender != this)
{
if (nMessage == WM_KEYDOWN && nChar == VK_TAB)
{
CWnd* pDlg = GetParent();

while (pDlg && !pDlg->IsKindOf(RUNTIME_CLASS(CDialog)))

pDlg = pDlg->GetParent();
if (pDlg)
{
CWnd* pWndNext = pDlg->GetNextDlgTabItem(m_pGridWnd);

if (pWndNext != NULL)
{

TRACE("SetFocus ");
pWndNext->SetFocus();
return TRUE;
}
}
}
}

return CGXGridWnd::ProcessKeys(pSender, nMessage, nChar, nRepCnt, flags);

}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 512
Last updated: 16 Apr, 2018
Revision: 3
Views: 2529
Posted: 19 Jan, 2001 by Meltreger B.
Updated: 16 Apr, 2018 by Meltreger B.

Others in this category