如何给ListCtrl控件在指定的位置动态追加一列(急)

解决方案 »

  1.   


    CListCtrl::InsertColumn
    注意这个函数第一个参数的用法。
      

  2.   

    CListCtrl::InsertColumn
    int InsertColumn( int nCol, const LVCOLUMN* pColumn );int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );Return ValueThe index of the new column if successful or -1 otherwise.ParametersnColThe index of the new column.pColumnAddress of an LVCOLUMN structure that contains the attributes of the new column.lpszColumnHeadingAddress of a string containing the column’s heading.nFormatInteger specifying the alignment of the column. It can be one of these values: LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER.nWidthWidth of the column, in pixels. If this parameter is -1, the column width is not set.nSubItemIndex of the subitem associated with the column. If this parameter is -1, no subitem is associatied with the column.ResInserts a new column in a list view control.TheLVCOLUMN structure contains the attributes of a column in report view. It is also used to receive information about a column. This structure is described in the Platform SDK.
      

  3.   

    正好有代码: LV_COLUMN lvcol;  lvcol.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH; 
    lvcol.fmt=LVCFMT_LEFT;//居中
    int i=0;
    lvcol.pszText="1"; 
    lvcol.iSubItem=i; 
    lvcol.cx=40; 
    m_listCtrl.InsertColumn(i++,&lvcol);
    lvcol.pszText="2"; 
    lvcol.cx=50; 
    m_listCtrl.InsertColumn(i++,&lvcol);
    lvcol.pszText="3"; 
    lvcol.cx=60; 
    m_listCtrl.InsertColumn(i++,&lvcol);
    lvcol.pszText="4"; 
    lvcol.cx=40; 
    m_listCtrl.InsertColumn(i++,&lvcol);
    lvcol.pszText="5"; 
    lvcol.cx=80; 
    m_listCtrl.InsertColumn(i++,&lvcol);
      

  4.   

    自己的代码,你看看有没有参考价值,多看msdn
    m_listctrl2.InsertColumn(0   ,     "评估内容",             LVCFMT_CENTER,   80,       0   );   
    m_listctrl2.InsertColumn(1   ,     " ",             LVCFMT_LEFT,   300,       1   );   
    m_listctrl2.InsertColumn(2   ,     "权重",                  LVCFMT_CENTER,  80,       2   );    
    m_listctrl2.ModifyStyle(   LVS_TYPEMASK,LVS_REPORT   |   LVS_SINGLESEL   );   
    m_listctrl2.SetExtendedStyle(       LVS_EX_FULLROWSELECT   | LVS_EX_GRIDLINES   |LVS_EX_HEADERDRAGDROP   |   LVS_EX_ONECLICKACTIVATE     );