Objective Grid: Adding a toolbar to a MDI child window with a CGXGridView

Article ID: 511
Last updated: 16 Apr, 2018
Article ID: 511
Last updated: 16 Apr, 2018
Revision: 3
Views: 2388
Posted: 11 Jan, 2001
by Meltreger B.
Updated: 16 Apr, 2018
by Meltreger B.

Problem


How do I add a toolbar to an MDI child window with a CGXGridView? I've added the toolbar per MS KBase article Q155141, but my app keeps ASSERTING before anything is visible.


Cause


The problem occurs because the toolbar posts OnUpdateCommandUI() command messages before Grid's OnInitialUpdate() is called. This means that m_pParam is NULL when CanCut(), CanEdit(), CanPaste(), etc... are called.
 


Action


To get around this, you need to include a check in your OnUpdateCommandUI() handler for m_pParam == NULL.

Example:

        void CMyGridView::OnUpdateEditCopy(CCmdUI* pCmdUI)
        {
                if(m_pParam) 
                        CGXGridView::OnUpdateEditCopy(pCmdUI); 
        }

You can also disable all OnUpdate() notifications until the grid has been correctly initialized by overriding OnCmdMsg():

        BOOL CMyGridView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
        {
                if (m_pParam == NULL || !m_bInitDone)
                        return TRUE;
        
                return CGXGridView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
        }

 

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

Others in this category