MFC Grid manual

How to get value from a cell? How to set a new value?

//Declaration of a data object

class CTestClass : public Dapfor::Common::CDataObject
{
    enum
    {
        FidPrice,
    };  

    double GetPrice() const {return ...;}
    void   SetPrice(double newPrice) {...; NotifyUpdate(FidPrice);}
};

DF_BEGIN_FIELD_MAP(CTestClass)
    DF_DOUBLE_ID(FidPrice,    "Price",    &CTestClass::GetPrice,   &CTestClass::SetPrice, 0)
DF_END_FIELD_MAP()



//There are many ways to get a non-formatted value from a grid cell
//1. If you have a pointer to the object of your class
CTestClass* testClass;
double price = testClass->GetPrice();

//2. If you have a pointer to the data object and don't want to cast to the CTestClass type:
Dapfor::Common::CDataObject* testClass = new CTestClass();
double price = testClass->GetDouble(CTestClass::FidPrice);
//or
double price = testClass->GetValue(CTestClass::FidPrice);


//3. Get the value directly from the grid. Note, that you get the typed value!
//For Datfor::GUI::CPreferences::DirectCall mode the grid will get data from the data object
//by calling GetPrice() method.
//For Datfor::GUI::CPreferences::MemoryBuffer mode the grid will return value from the cache.
double price = m_Grid.GetValue(hItem, CTestClass::FidPrice);


//In the same way you can get formatted values as MFC or STL strings
Dapfor::Common::CDataObject* testClass = ...;
CString mfcText = testClass->GetFormattedMfcString(CTestClass::FidPrice, 0);
std::string stlText = testClass->GetFormattedStlString(CTestClass::FidPrice, 0);

//Or from the grid:
CString mfcText = m_Grid.GetFormattedMfcString(hItem, CTestClass::FidPrice);
std::string stlText = m_Grid.GetFormattedStlString(hItem, CTestClass::FidPrice);


//The preferred way to set a new value is to implement a notification mechanism 
//in the data object and to call Set- method.
CTestClass* testClass = new CTestClass();
test->SetPrice(...);

//Of course, you can call 
m_Grid.SetValue(hItem, CTestClass::FidPrice, (double)1.23);
testClass->SetValue(CTestClass::FidPrice, (double)1.23);

//Alternatively, if you want to transform MFC/STL string to a value, you can use the following
m_Grid.SetFormattedMfcString(hItem, CTestClass::FidPrice, "1.23");
testClass->SetFormattedMfcString(CTestClass::FidPrice, "1.23", 0);