void CPrintsysDlg::AdjustColumnWidth()
{
//SetRedraw(FALSE);
int nColumnCount = GetColumnCount();
for (int i = 0; i < nColumnCount; i++)
{
m_list.SetColumnWidth(i, LVSCW_AUTOSIZE);
int nColumnWidth =m_list. GetColumnWidth(i);
m_list.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER);
int nHeaderWidth = m_list.GetColumnWidth(i);
m_list.SetColumnWidth(i, max(nColumnWidth, nHeaderWidth));
}
// SetRedraw(TRUE);
}
int CPrintsysDlg::GetColumnCount()
{
CHeaderCtrl* pHeaderCtrl =m_list. GetHeaderCtrl();
return (pHeaderCtrl->GetItemCount());
}
As we can see, this function calculates the widths of the Column Headers as well as the Items and sets the width to the larger of the two, so that complete header is visible even if no item is inserted. Also note that the last column will take all the remaining space.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/li_zw/archive/2007/12/29/2003304.aspx