-1

I have customized the column width CMFCPropertyListCtrl by overriding the same class.
Code:

class CMyPropertyGridCtrl : public CMFCPropertyGridCtrl
{
public:
    void SetFirstColumnWidth(int width)
    {
        m_nLeftColumnWidth = width;
        AdjustLayout();
    }
};

And in OnSize() method of the class where pChannelListCtrl is declare as data member, I have called this method. I want to fixed second column with size 50.
Code:

int iWidth = pChannelListCtrl.GetLeftColumnWidth();
pChannelListCtrl.SetFirstColumnWidth(iWidth + (iWidth - 50));

Here, its display as expected.(Second column with size 50).
Problem: I want to keep the second column size fixed. But, here its resizable.

Can you please guide me, how to restrict the column resize.

Thanks,
Abdula

AB Bolim
  • 1,997
  • 2
  • 23
  • 47
  • I have already refereed this : https://stackoverflow.com/questions/3453244/how-to-set-a-cmfcpropertylistctrls-column-width – AB Bolim Oct 12 '18 at 13:00

1 Answers1

0

Override CMFCPropertyGridCtrl::SetLeftColumnWidth.

The header control for the grid is accessed with CMFCPropertyGridCtrl::GetHeaderCtrl()

Optionally, you can disable the header control to prevent resizing GetHeaderCtrl().EnableWindow(FALSE);

class CMyPropertyGridCtrl : public CMFCPropertyGridCtrl
{
public:
    CMyPropertyGridCtrl()
    {
        m_nLeftColumnWidth = 50;
    }

    void make_fixed_header()
    {
        HDITEM hdItem = { 0 };
        hdItem.mask = HDI_FORMAT;
        GetHeaderCtrl().GetItem(0, &hdItem);
        hdItem.fmt |= HDF_FIXEDWIDTH;
        GetHeaderCtrl().SetItem(0, &hdItem);
    }

    void SetLeftColumnWidth(int cx)
    {
        m_nLeftColumnWidth = cx;
        AdjustLayout();
    }

    void OnSize(UINT f, int cx, int cy)
    {
        EndEditItem();
        if (cx > 50)
            m_nLeftColumnWidth = cx - 50; //<- 2nd column will be 50 pixels
        AdjustLayout();
    }

    DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CMyPropertyGridCtrl, CMFCPropertyGridCtrl)
    ON_WM_SIZE()
END_MESSAGE_MAP()

Use HDF_FIXEDWIDTH to fix the column for header control. From parent window call these functions after the control is created:

grid.SetLeftColumnWidth(50);
grid.make_fixed_header();

CMyPropertyGridCtrl::SetLeftColumnWidth will not detect when column is resized by the user. Override CMyPropertyGridCtrl::OnHeaderItemChanged in order to detect changes requested by user.

Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77
  • `GetHeaderCtrl().EnableWindow(FALSE);` can not prevent resizing. And I want to fixed size of **Second Column** and not First column. – AB Bolim Oct 12 '18 at 12:16
  • I think I misunderstood the question. See edit. Add `ON_WM_SIZE` message, override `CMFCPropertyGridCtrl::OnSize` as shown, to change the column when the whole control is resized. – Barmak Shemirani Oct 12 '18 at 12:41
  • There is no issue when whole control is resize. Second column width remain same, as I am calling `SetFirstColumnWidth()`. I want to hide/disable the splitter that change the width of the first and second column. – AB Bolim Oct 12 '18 at 12:49
  • If I override `OnSize` method of `CMFCPropertyGridCtrl`, the second column is disappear. Even I tried out with different width. – AB Bolim Oct 12 '18 at 12:58
  • You are changing the question. See the third edit. `make_fixed_header` will stop the header from resizing if that's what you want. `OnSize` should behave as expected unless width is less than 50, or unless other changes are made. – Barmak Shemirani Oct 12 '18 at 13:09
  • I am not changing the question, just providing more info so u get it the actual problem statement. I have tried out your latest edit section, but no luck. Still column are resizable. I want to fixed the size even user change the size of Dockpane. – AB Bolim Oct 15 '18 at 08:41