How to set a minimum column width

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


Again we have to override the OnNotify() function. The
code below restricts the columns to a minimum width of 80 pixels. The logic
can be extended to restrict the width within a range or even specify different
range for different columns. To extend the functionality, you would need
to add member variables to the class to track the different settings.

BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
{
    HD_NOTIFY   *pHDN = (HD_NOTIFY*)lParam;

        if((pHDN->hdr.code == HDN_ITEMCHANGINGW || pHDN->hdr.code == HDN_ITEMCHANGINGA) 
                && pHDN->pitem->cxy < 80)
        {
                *pResult = TRUE;                // disable change
                return TRUE;                    // Processed message
        }
 
        return CListCtrl::OnNotify(wParam, lParam, pResult);
}

 

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read