List View Collumns

John Boehme (jandce@iglobal.net)
Wed, 02 Oct 1996 08:00:59 -0500

Environment: VC 4.0/Win 95

I have a list view to display a set of information in report format.
When I create the list and define the headers, I use the function
GetStringWidth to get the column width necessary top display the column
title. The problem is that the function returns 14, always.

When the columns are displayed, they are only wide enough to display the
first character followed by a couple of periods.

I define the columns in OnInitialUpdate of my view. I have tried the
following code:

CStringArray cHeader;
cHeader.Add( "File" );
..
..
lvcolumn.cx = listCtrl.GetStringWidth( cHeader[i] );
--------------------------
char cHeader[ROWS][TITLELEN] = {"File","Loc.",....};
..
..
lvcolumn.cx = listCtrl.GetStringWidth( cHeader[i] );
--------------------------
lvcolumn.cx = listCtrl.GetStringWidth( "File" );
--------------------------

My create statement looks like the following:

BOOL StatsView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD
dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext*
pContext)
{
// TODO: Add your specialized code here and/or call the base class

return CWnd::Create(lpszClassName, lpszWindowName, dwStyle | LVS_REPORT |
LVS_NOLABELWRAP, rect, pParentWnd, nID, pContext);
}
I get the same result if I do, or do not, include the LVS_NOLABELWRAP option
in my create style.

It appears that 14 could be the width of the first character only. The
documnetation does not state that I need to multiply this value by the
length of the string.

Is OnInitialUpdate the wrong place to define the headers? Do I need to
perform some other action to define the font for the view?

Thanks in advance for any assistance.
John Boehme
jandce@iglobal.net
http://www.iglobal.net/pub/JohnAndCe