Problem with Horizontal scroll bar in CListCtrl
I am trying to remove the horizontal scrollbar from a CListCtrl-derived control,
and I can't seem to make it work. I want to retain the vertical scroll bar, but
not the horizontal.
I've already added:
ModifyStyle(WS_HSCROLL, 0)
to:
OnCreate()
PreSubclassWindow()
OnWindowPositionChanging()
but the horizontal scroll bar will not go away!
The app is dialog based, and the dialog is the main window. The list control is
created via a dialog resource, and I'm not using Create(), but that shouldnt
matter.
If I set the "No Scroll" style in the resource editor, then I get no scroll bars
and I can add the vertical bar with ModifyStyle(0, WS_VSCROLL), but then of
course the control won't scroll anyway even using the scroll bar (and
EnsureVisible doesn't work either).
This leads me to believe that it is the header control that is somehow "turning
on" the horizontal scroll bar. One thing I do do is size the columns to fit
each time I repopulate the control:
void CMyListCtrl::AutosizeColumns()
{
CHeaderCtrl* pHdr = GetHeaderCtrl();
ASSERT(pHdr);
if (pHdr)
{
// Turn off redraw until the columns have all
// been resized
SetRedraw(FALSE);
for (int iCurrCol = 0; iCurrCol < pHdr->GetItemCount();
iCurrCol++)
{
SetColumnWidth(iCurrCol, LVSCW_AUTOSIZE);
int nCurrWidth = GetColumnWidth(iCurrCol);
SetColumnWidth(iCurrCol, LVSCW_AUTOSIZE_USEHEADER);
int nColHdrWidth = GetColumnWidth(iCurrCol);
SetColumnWidth(iCurrCol, max(nCurrWidth, nColHdrWidth));
}
}
// Now that sizing is finished, turn redraw back on and
// invalidate so that the control is repainted
ModifyStyle(WS_HSCROLL, 0);
SetRedraw(TRUE);
Invalidate();
}
I don't think this is the culprit, since I created a quick test app, put a list
control on a dialog, subclassed it and added this Autosize columns routine, and
in the simple test app I can get rid of the horizontal scroll bar.
Each time the control is repopulated, all rows are deleted and all columns too,
and then the control is repopulated (columns and rows) with the results of a
database query.
If anyone has some insight into how a populating the control or perhaps
resizingit is somehow setting the WS_HSCROLL style, or if anyone has some ideas
about how I can find out when/why that style is getting changed, that would be
most appreciated.
Thanks a bunch!
Mike