I'm adding properties to an object of type CMFCPropertyGridCtrl
like this:
myPropertyListCtrl.AddProperty(
new CMFCPropertyGridProperty(
_T("Name"),
foo.GetName())
);
The result is that only the second column is visible but not the first that should contain "Name".
CMFCPropertyGridCtrl::GetPropertyColumnWidth()
but there appears to be no corresponding Set...
method...NewControls
sample, in which the column sizing appears to be fully automatic. However, I couldn't find the relevant difference to my code.What am I missing?
m_nLeftColumnWidth
responsible for holding the "Name" column's width is a protected
member of the CMFCPropertyGridCtrl
class. Create your own class, that derives from CMFCPropertyGridCtrl
and you will be able to manipulate m_nLeftColumnWidth
.
Note that m_nLeftColumnWidth is initially set to 0 in CMFCPropertyGridCtrl's ctor. One of the few other places that it is set, is in the OnSize() method (ref. AfxPropertyGridCtrl.cpp, line 2783 in VS2010), where it is set to half the width of the grid. This may not be ideal, nor the customized value described by overriding the class to explicitly set it, but may be good enough.
If so, then it is merely to trigger having the CMFCPropertyGridCtrl::OnSize() protected method. When used in a resizable window such as a CDockablePane, OnSize() will be called automatically. But in a CDialog, it needs to be trigger explicitly such as to send a WM_SIZE message:
CRect rect;
myPropGrid.GetWindowRect(&rect);
myPropGrid.PostMessage(WM_SIZE, 0, MAKELONG(rect.Width(),rect.Height()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With