MFC Grid manual

How to get grid notification from a C++ object?

//When Set- method of an object (e.g. SetPice) is called, 
//all grids containing the object receive notifications.
//Notifications can be sent from any thread. When the grid 
//receives a notification, the row that corresponds to the object is automatically 
//moved to the appropriate position according to sorting, filtering 
//and hierarchical rules, and the relevant cell of the grid is highlighted.


// MyClass.h file
class CMyClass : public Dapfor::Common::CDataObject
{
public:
    // It is useful to use enumerations instead of long numeric values...
    // The grid can use the same identifiers to show values returned 
    // by functions of this class.
    enum
    {
        FidPrice,
        ...
    };

public:

    //Get- methods
    double  GetPrice() const;
    ...

    //Set- methods
    void  SetPrice(double newPrice);
    ...


private:
    double  m_Price;
    ...

    //Declaration of map containing the list of functions 
    //that can be called by their identifiers.
    DF_DECLARE_FIELD_MAP();
};




//MyClass.cpp file


// Declaration of a field map.
// To put an object of CMyClass into the grid, it should declare a table 
// that enables calls of specified functions by identifiers. 
// We can customize a presentation using formats included in Common 
// library or custom formats.
DF_BEGIN_FIELD_MAP(CMyClass)
    DF_DOUBLE_ID(FidPrice,    "Price",    &CMyClass::GetPrice,    &CMyClass::SetPrice, 0)
    ...
DF_END_FIELD_MAP()


//Get- methods.
double  CMyClass::GetPrice() const
{
    return m_Price;
}

...

//Set- methods.
void  CMyClass::SetPrice(double newPrice)
{
    if(m_Price != newPrice)
    {
        m_Price = newPrice;
        //Send a notification to all listeners.
        NotifyUpdate(FidPrice);
    }
}