First of all, your dialog class should have at least DECLARE_DYNAMIC
/IMPLEMENT_DYNAMIC
in its declaration/implementation. This will allow you to use DYNAMIC_DOWNCAST
/STATIC_DOWNCAST
in grid’s code:
void CYourGrid::OnGridCellInputComplete(
CExtGridCell & _cell,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
HWND hWndInputControl // = NULL
)
{
ASSERT_VALID( this );
__super::OnGridCellInputComplete( _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
CWnd * pWndParent = GetParent();
CYourDialog * pYourDialog = DYNAMIC_DOWNCAST( CYourDialog, pWndParent );
if( pYourDialog != NULL )
pYourDialog->SomeMethod( . . . );
}
If you don’t like this approach, then you can use interfaces. First of all, you will need to declare interface with events you need. For instance:
interface IMyGridEvents
{
virtual void MyGridEvents_OnGridCellInputComplete(
CExtGridWnd & wndGrid,
CExtGridCell & _cell,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
HWND hWndInputControl = NULL
) = 0;
};
Then you will need to learn your grid control to use your interface. So, the grid class should look like:
class CYourGrid : public CExtGridWnd
{
public:
IMyGridEvents * m_pMyGridEvents;
CYourGrid()
: m_pMyGridEvents( NULL )
{
}
virtual void OnGridCellInputComplete(
CExtGridCell & _cell,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
HWND hWndInputControl = NULL
)
{
ASSERT_VALID( this );
__super::OnGridCellInputComplete( _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
if( m_pMyGridEvents != NULL )
m_pMyGridEvents->MyGridEvents_OnGridCellInputComplete( *this, _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
}
};
Now you can use this grid class in your dialog class. But you should learn the dialog to receive grid events through the interface. So, the dialog class should look like:
class CYourDialog : public CExtNCW < CExtResizableDialog >, public IMyGridEvents
{
public:
CYourGrid m_grid;
CYourDialog()
{
m_grid->m_pMyGridEvents = this;
}
virtual void MyGridEvents_OnGridCellInputComplete(
CExtGridWnd & wndGrid,
CExtGridCell & _cell,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
HWND hWndInputControl = NULL
)
{
ASSERT_VALID( this );
}
};
We have the
wndGrid
parameter in the interface method. This allows us to use it for receiving events from more than one grid control.