Professional UI Solutions
Site Map   /  Register


Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » How to work with the CExtGridWnd ? Collapse All
Subject Author Date
Sebastian Leopold Apr 20, 2008 - 6:26 AM


I dont understand how to work with the "CExtGridWnd" class. I understand how to add Columns and fill it with Data but, how can I get any events from the Grid. Are there any window messages wich are thrown ?? or do I have to derive a class from CExtGridWnd and override some virtual methods to get the events.

How can I get a event when a cell get selected ? I need that because I want to update some Controls on grid selection ?




Technical Support Apr 22, 2008 - 8:52 AM

Any events can be handled through the grid’s virtual methods. As for the selection changed event, you can do this by overriding the OnGbwSelectionChanged() virtual method.

There is a FAQ at our website How to get the selected row indexes from the grid window, or change selections programmatically?, which can be helpful in this regard.

D. Cameron DeHeer Apr 22, 2008 - 7:42 AM

Hi Sebastian,

I ran into the same issue and ended up subclassing the grid control as CGridWnd and overloading OnGbwSelectionChanged and OnGridCellInputComplete to post user-defined messages to the parent window.  Some other overrides would be nice for item inserts, deletes, etc. as well, but I haven’t added them yet.  Code snippets for these is below, the GN_SELECTIONCHANGED and GN_CELLINPUTCOMPLETE are #defined as offsets from WM_USER.  I would be interested to hear someone from Prof-UIS or other users to give their insight on this, however, because in general I think it would be nice if this was supported out of the box.  Hope this helps.




void CGridWnd::OnGbwSelectionChanged()







void CGridWnd::OnGridCellInputComplete(CExtGridCell &_cell,

           LONG nColNo,

           LONG nRowNo,

           INT nColType,

           INT nRowType,

           HWND hWndInputControl)












Technical Support Apr 24, 2008 - 7:23 AM

Of course, with some additional efforts you can implement any notification algorithm and your solution is suitable. We already helped some of our users to make the grid events compatible with its existing handler for the NM_CLICK notification. In this we can generate this notification ourselves as follows:

void CMyGridWnd::OnGbwFocusChanged(
            const POINT & ptOldFocus,
            const POINT & ptNewFocus
            ASSERT_VALID( this );

            CWnd * pWndOwner = GetOwner();
            if(                     pWndOwner->GetSafeHwnd() == NULL 
                        ||          (!::IsWindow( pWndOwner->m_hWnd ))
            ASSERT_VALID( pWndOwner );

            CPoint ptCursor( 0, 0 );
            ::GetCursorPos( &ptCursor );

            NMCLICK nmclick;
            nmclick.hdr.code = NM_CLICK;
            nmclick.hdr.idFrom = GetDlgCtrlID();
            nmclick.hdr.hwndFrom = GetSafeHwnd();
   = ptCursor;

                        (LPARAM) (NMHDR*) &nmclick
Then add the following line to the message map
So the existing OnClickList1() handler will be invoked automatically:
void CTest_simple_gridDlg::OnClickList1( NMHDR * pNMHDR, LRESULT * pResult ) 
            CPoint ptFocus = m_wndGrid.FocusGet();
            CString sLog;
                        _T("FOCUSED ITEM: row: %d, column: %d"),
                        ptFocus.y, ptFocus.x

            m_wndLabelLog.SetWindowText( sLog );
            *pResult = 0;
If you have handled some other notification messages, you can generate them in the same way. You can also declare a custom message and send it from grid’s overridden methods to the parent dialog.

Here is the sample where this code is used.