Dapfor home  

How to notify the grid from the C++ object?

//When Set- method of the object (for example SetPice) is called, 
//all grids, where the object has been inserted, receive notifications.
//The notifications can be sent from any thread. When the grid 
//receives them, the row corresponding to the object will be automatically 
//moved to the appropriate position according to sorting, filtering 
//and hierarchical rules and the grid's cell will be highlighted.


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

public:

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

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


private:
    double  m_Price;
    ...

    //Declaration of the map, that contains 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 the table, 
// which permits to call specified functions by its identifiers. 
// Also, we can customize a presentation using the formats, included in Common 
// library or our 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);
    }
}


Copyright Dapfor 2007-2009
Generated on Sat Jan 30 15:01:23 2010 for MFCGrid by doxygen 1.5.5