我需要设定ListView每一栏的宽度,但是MSDN中只有自动设置,怎样设定自己需要的宽度?
请各位高手帮忙,不胜感激

解决方案 »

  1.   

    不是高手,最近手头有这个例子,我也没完全看懂,但相信能满足你的要求。
    // the heading text is in the format column 0 text,column 1 width;column 2 text,column 3 width;etc.
    BOOL CSortListCtrl::SetHeadings( const CString& strHeadings )
    {
    int iStart = 0; for( ;; )
    {
    const int iComma = strHeadings.Find( _T(','), iStart ); if( iComma == -1 )
    break; const CString strHeading = strHeadings.Mid( iStart, iComma - iStart ); iStart = iComma + 1; int iSemiColon = strHeadings.Find( _T(';'), iStart ); if( iSemiColon == -1 )
    iSemiColon = strHeadings.GetLength(); const int iWidth = atoi( strHeadings.Mid( iStart, iSemiColon - iStart ) );

    iStart = iSemiColon + 1; if( InsertColumn( m_iNumColumns++, strHeading, LVCFMT_LEFT, iWidth ) == -1 )
    return FALSE;
    } return TRUE;
    }调用:m_SortListCtrl.SetHeadings( _T("Name,50;Access time,150;Length,50;") ); ///设置列头信息
      

  2.   

    通过GetListCtrl 获得CListCtrl后用
    SetColumnWidth设置列宽