MFC Grid manual

Notifications

The grid can inform its owners about some events, such as addition of a new line, selection or focus changes, etc. The given information is sent in form of WM_NOTIFY message, where one of the structures containing the detailed information about an event is stored in the lParam. For improving grid productivity it is possible to block event sending by calling CGrid::AllowNotifications() function.

List of available notifications:

The following example demonstrates how to get notications from the grid

1. You have a class that contains the GGrid object

//File SomeDialog.h

using namespace Dapfor;
class CSomeDialog : public CDialog
{
...
protected:
    afx_msg void OnSelectionChanged(NMHDR*, LRESULT*);
    afx_msg void OnExpansionChanged(NMHDR*, LRESULT*);

private:
    GUI::CGrid m_Grid;
}; 


  
//File SomeDialog.cpp
BEGIN_MESSAGE_MAP(CSomeDialog, CDialog)
    ...
    ON_NOTIFY(Dapfor::GUI::Notifications::SelectionChanged, IDC_CUSTOM1, OnSelectionChanged)
    ON_NOTIFY(Dapfor::GUI::Notifications::ExpansionChanged, IDC_CUSTOM1, OnExpansionChanged)
END_MESSAGE_MAP()

void CSomeDialog::OnSelectionChanged(NMHDR* hdr, LRESULT* lresult)
{
    Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
    //Your implementation...
}
  
void CSomeDialog::OnExpansionChanged(NMHDR* hdr, LRESULT* lresult)
{
    Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
    //Your implementation...
}

2. If you have your own control that derives from the grid, you can use the following:

//File CustomGrid.h
#include <Dapfor/GUI/Grid.h>

class CCustomGrid : public Dapfor::GUI::CGrid
{
protected:
    afx_msg void OnLButtonDown(UINT flags, CPoint point);
    afx_msg void OnExpansionChanged(NMHDR*, LRESULT*);

    DECLARE_MESSAGE_MAP()
};


//File CustomGrid.cpp
#include <Dapfor/GUI/Notifications.h>

BEGIN_MESSAGE_MAP(CCustomGrid, Dapfor::GUI::CGrid)
    ON_WM_LBUTTONDOWN()
    ON_NOTIFY_REFLECT(Dapfor::GUI::Notifications::ExpansionChanged, OnExpansionChanged)
END_MESSAGE_MAP()

void CCustomGrid::OnLButtonDown(UINT flags, CPoint point)
{
    //Don't forget to call the method of the base class
    CGrid::OnLButtonDown(flags, point);
}
  
void CCustomGrid::OnExpansionChanged(NMHDR* hdr, LRESULT* lresult)
{
    Dapfor::GUI::NM_GRIDITEM* item = (Dapfor::GUI::NM_GRIDITEM*)hdr;
    ...
}