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!