Share via


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.

Example

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

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

LB_SETCOLUMNWIDTH