0

I have several properties that are floats. By default, the CMFCPropertyGridProperty displays these with 6 decimal places. I want them to display with 2 decimal places as in 12.75 vs 12.750000. So I put in the following line:

CMFCPropertyGridProperty::m_strFormatFloat = "%.2f";

That makes it display correctly with 2 decimal places. But when I change the value, %.2f is not a valid scanf format, so the program blows up.

I tried overriding the FormatProperty() function like this:

class PropertyGrid2Digits : public CMFCPropertyGridProperty
{
public:
    PropertyGrid2Digits(const CString& strName, const float InitialValue = 0, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0);
    virtual ~PropertyGrid2Digits();
    virtual CString FormatProperty() {
        CString str;
        str.Format("%.2f", GetValue().fltVal);
        return str;
    }
};

but my version only gets called when the property is first created. Somehow, the CMFCPropertyGridProperty::FormatProperty() function gets called whenever the property gets painted.

Does anybody know how I can fix this? Thanks!

John Frickson
  • 179
  • 1
  • 3
  • 16
  • Your question is a bit confusing "the CMFCPropertyGridProperty::FormatProperty() function gets called whenever the property gets painted" -- so what exactly is the problem with `CMFCPropertyGridProperty::FormatProperty()`? – Edward Clements Jun 28 '13 at 08:07
  • The base `FormatProperty()` function gets called, not my override. – John Frickson Jun 28 '13 at 15:57
  • The only reason I can think of why that can happen is not all property items have been created with `new PropertyGrid2Digits(...)` – Edward Clements Jun 28 '13 at 16:23

0 Answers0