Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a CMFCPropertyListCtrl's column width?

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".

  • I found CMFCPropertyGridCtrl::GetPropertyColumnWidth() but there appears to be no corresponding Set... method...
  • I looked at the 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?

like image 274
foraidt Avatar asked Aug 10 '10 20:08

foraidt


2 Answers

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.

like image 194
Aoi Karasu Avatar answered Sep 22 '22 08:09

Aoi Karasu


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()));
like image 21
David Carr Avatar answered Sep 24 '22 08:09

David Carr