I am trying to validate certain fields by overriding CGXODBCGrid::OnFlushRecord. I am able to display message box to the user. But, after I display warning message to the user, I would like to move focus to the cell with invalid data. How can I do that?
To set the focus on the offending cell that you validated on OnFlushRecord:
Declare member var, m_nOffCol to denote the offending column.
Do this override in your browser view:
BOOL CDaobrowsView::SetCurrentCell(ROWCOL nRow, ROWCOL nCol, UINT flags)
{
ROWCOL nCurRow, nCurCol;
GetCurrentCell(nCurRow,nCurCol);
CGXBrowseParam* pBrowseData = (CGXBrowseParam*)GetParam();
// If current row has been changed and current cell is positioned to a new row
if (pBrowseData->m_nEditMode != noMode && nRow && nRow != nCurRow)
{
CString s;
if (!Update(&s))
{
if (!s.IsEmpty())
SetWarningText(s);
return CGXDaoRecordView::SetCurrentCell(nCurRow,m_nOffCol,flags|GX_DISPLAYEDITWND);
}
}
//Call the base class
return CGXDaoRecordView::SetCurrentCell(nRow,nCol,flags);
}
Set m_nOffCol with the offending col during your validation in OnFlushRecord and return FALSE in OnFlushRecord if invalid.
This will set the focus to the offending cell when you move to a different row.