对话框的BOOL CListKuohaoDlg::OnInitDialog() 
{
........for(int i=0;i<5;i++)
 {
LVColumn.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_IMAGE|LVCF_WIDTH|LVCF_ORDER;
 LVColumn.fmt=LVCFMT_LEFT;
 LVColumn.pszText=rgtsz[i];
 LVColumn.iSubItem=i;
 LVColumn.iOrder=i;
 LVColumn.cx=rectlist.Width()*1/5;
     Result= m_listKuohao.InsertColumn(i,&LVColumn);
 } int nIndex=m_listKuohao.GetItemCount();//nIndex=0 LV_ITEM   lvitemAdd = {0};
  lvitemAdd.mask = LVIF_TEXT;
  lvitemAdd.iItem = 0 ;
  lvitemAdd.state=0;
  lvitemAdd.iSubItem = 0;
  lvitemAdd.pszText =_T("胜利");
  int n=m_listKuohao.InsertItem(&lvitemAdd);
  int nIndextest=m_listKuohao.GetItemCount();//nIndextest=1
跟踪到这里我想程序应该没错吧,但是程序运行时就会报个错误提示说插入错误void CListCtrl::DrawItem(LPDRAWITEMSTRUCT)
{
ASSERT(FALSE);//指示这里出错
}
谁能告诉我是哪出问题了呢?如果没有蓝色这一段,就不会报错,显示一个空的5列表格。

解决方案 »

  1.   

    把你蓝色的代码,直接改成如下这样就可以了:
    CString strText = _T("胜利");
    m_listKuohao.InsertItem(nIndex,strText);//这样就可以插入一行了,nIndex为0,表示插入第一行,并且第一列会显示“胜利” 
    m_listKuohaoSetItemText(nIndex,1,_T("..."));//设置第一行第二列的值
    m_listKuohaoSetItemText(nIndex,2,_T("..."));//设置第一行第三列的值...
      

  2.   

    你的listctrl的属性是怎么设置的?是不是设置成自绘制了?把owner draw取消,你那样插入应该也是没问题的。
      

  3.   


    BOOL CprogressDlg::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    // TODO: Add extra initialization here
    //设置显示样式
    m_progresslistctrl.ModifyStyle(0L, LVS_REPORT); //设为Report类型
    m_progresslistctrl.ModifyStyle(0L, LVS_SHOWSELALWAYS); //始终高亮度被选中的表项
    m_progresslistctrl.SetExtendedStyle( LVS_EX_FULLROWSELECT | //允许整行选中
    LVS_EX_HEADERDRAGDROP | //允许整列拖动
    LVS_EX_GRIDLINES  //画出网格线
    // LVS_EX_FLATSB //扁平风格的滚动条
    );
    //m_progresslistctrl.InsertColumn(0, "Status",LVCFMT_LEFT,-1,-1); m_progresslistctrl.InsertColumn(0,"File Name",LVCFMT_LEFT,-1);    m_progresslistctrl.InsertColumn(3,"Progress",LVCFMT_LEFT,-1);
    //m_progresslistctrl.SetColumnWidth(0,7);
    m_progresslistctrl.SetColumnWidth(0,100); m_progresslistctrl.SetColumnWidth(1,200);
      
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }
      

  4.   

    你是不是设置了“Owner Draw”风格?
      

  5.   

    http://blog.csdn.net/compassbutton/archive/2007/10/31/1859528.aspx
    这里有listctrl的使用,你看看,希望对你有帮助