This documentation is archived and is not being maintained.

CListBox::SetColumnWidth

Sets the width in pixels of all columns in a multicolumn list box (created with the LBS_MULTICOLUMN style).

void SetColumnWidth(
   int cxWidth 
);

cxWidth

Specifies the width in pixels of all columns.


// Find the pixel width of the largest item.
CString str;
CSize   sz;
int     dx = 0;
CDC*    pDC = myListBox.GetDC();
for (int i=0;i < myListBox.GetCount();i++)
{
   myListBox.GetText( i, str );
   sz = pDC->GetTextExtent(str);

   if (sz.cx > dx)
      dx = sz.cx;
}
myListBox.ReleaseDC(pDC);

// Set the column width of the first column to be one and 1/3 units
// of the largest string. 
myListBox.SetColumnWidth(dx*4/3);


Header: afxwin.h

Show: