c++scrollbarclistctrl

CListCtrl with HSCROLL disabled - cannot select last visible item


I have a simple dialog box with a CListCtrl. The list control is in report view and only has one column.

I've disabled the horizontal scroll of my list by overriding the OnNcCalcSize() function

void CMyListCtrl::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS * lpncsp)
{
    // disable horizontal scroll bar
    ModifyStyle(WS_HSCROLL, 0);

    CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}

I'm catching the selection change by handling the NM_CLICK message but, for some reason, this is not called when clicking on the last visible item in the list. The bottom arrow of the vertical scroll bar is also not visible initially, and it is not scrolling when I click that either. Basically, everything in the red square is not receiving the click message.

no Scroll Scroll

I'm pretty sure this is because I've disabled the horizontal scroll bar, because it's pretty much the area where the horizontal scroll bar should be.

Has anyone else seen this? Any way I can catch the click message in this area?


Solution

  • I've found a workaround by resizing the column to the width of the client area of the list control in OnNcCalcSize()

    void CMyListCtrl::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS * lpncsp)
    {
        // disable horizontal scroll bar
        ModifyStyle(WS_HSCROLL, 0);
    
        CRect rect;
        GetClientRect(&rect);
        SetColumnWidth(0, rect.Width());
    
        CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
    }
    

    This works because the client rect does not include the vertical scroll bar.

    The user can still resize the column themselves, but with the HSCROLL disabled it seems they cannot make it wider than the control.