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 
);

Parameters

cxWidth

Specifies the width in pixels of all columns.

// The pointer to my multicolumn list box.
extern CListBox* pmyListBox;

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

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

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