CListView不能设置列内容 RRS feed

  • 问题

  • 程序基于MDI,我创建了一个视类继承自CListView,但不知为什么如下代码中

    void CMakefileView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* pHint)
     // TODO: Add your specialized code here and/or call the base class

     if(GetDocument() == pHint)
      int i = 0;
      CString strText;

      // TODO: Add your specialized code here and/or call the base class
      CListCtrl& listCtrl = GetListCtrl();

      vector<CItem>::iterator iter;
      vector<CItem>* pCont = (reinterpret_cast<CMakeGen2Doc*>(GetDocument()))->GetContPtr();

      for(iter = pCont->begin(); iter != pCont->end(); iter++, i++)
       strText.Format(TEXT("%d"), i);
       int nItem = listCtrl.InsertItem(i, strText);

       strText.Format(TEXT("%S"), iter->m_strLineCont.c_str());
       int nRet = listCtrl.SetItemText(nItem, 1, strText);   




    2011年6月13日 13:06


  • Debug调试下strText有值吗?
    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年6月14日 0:09
  • I am just on office, so I can only reply in English. Yes, it's endowed with literary value. Once I've tried

    int nRet = listCtrl.SetItemText(nItem, 1, _T("Test"));

    also nothing happened.

    MSDN is vague about the formatting string, I've typed

    strText.Format(TEXT("%s"), iter->m_strLineCont.c_str());

    here, the s in "%s" is in lower case, and seems strText is filled with rubbish, so I change the s in upper case, and it seems strText contains reasonable value:

    strText.Format(TEXT("%S"), iter->m_strLineCont.c_str());

    but also nothing happens.

    Another question, I've tried CListView in SDI, it seems all is OK, and the third parameter in the function OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* pHint) is also passed to a non-zero value when the function be called. But in my MDI counterpart, if the condition
    if(GetDocument() == pHint) be added, it's always false, and debugging shows that pHint is 0. I just can not understand why such a behaviour.

    Anyone can give a help or hint is thanked in advance.

    2011年6月14日 1:14