Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CListCtrl problem

CListCtrl problem

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingxmlhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jgauffin
    wrote on last edited by
    #1

    Hello Im using a CListCtrl and the subitems arent shown when I use the code below. If I put the code in OnInitialUpdate everything works. What's the problem? void CLogAnalyzerView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/) { CListCtrl& lst = GetListCtrl(); if (lHint == CLogAnalyzerDoc::VIEW_LOADDOC) { CMarkup& xml = GetDocument()->GetXml(); xml.FindElem("/log"); xml.IntoElem(); while (xml.FindElem("session")) { int iItem = 0; while (xml.FindChildElem("entry")) { iItem = lst.InsertItem(LVIF_TEXT, lst.GetItemCount(), xml.GetChildAttrib("stamp"), 0, 0, 0, 0); if (!lst.SetItemText(iItem, 1, xml.GetChildAttrib("prio"))) TRACE("%d\n", GetLastError()); lst.SetItemText(iItem, 2, xml.GetChildAttrib("t")); lst.SetItemText(iItem, 3, "baks"); lst.SetItemText(iItem, 4, xml.GetChildAttrib("group")); lst.SetItemText(iItem, 5, xml.GetChildData()); } } } }

    D V 2 Replies Last reply
    0
    • J jgauffin

      Hello Im using a CListCtrl and the subitems arent shown when I use the code below. If I put the code in OnInitialUpdate everything works. What's the problem? void CLogAnalyzerView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/) { CListCtrl& lst = GetListCtrl(); if (lHint == CLogAnalyzerDoc::VIEW_LOADDOC) { CMarkup& xml = GetDocument()->GetXml(); xml.FindElem("/log"); xml.IntoElem(); while (xml.FindElem("session")) { int iItem = 0; while (xml.FindChildElem("entry")) { iItem = lst.InsertItem(LVIF_TEXT, lst.GetItemCount(), xml.GetChildAttrib("stamp"), 0, 0, 0, 0); if (!lst.SetItemText(iItem, 1, xml.GetChildAttrib("prio"))) TRACE("%d\n", GetLastError()); lst.SetItemText(iItem, 2, xml.GetChildAttrib("t")); lst.SetItemText(iItem, 3, "baks"); lst.SetItemText(iItem, 4, xml.GetChildAttrib("group")); lst.SetItemText(iItem, 5, xml.GetChildData()); } } } }

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Does the while loop get executed as expected? Do the xml.Getxxx() calls return the expected data? Are any of the calls to SetItemText() failing?


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      J 1 Reply Last reply
      0
      • D David Crow

        Does the while loop get executed as expected? Do the xml.Getxxx() calls return the expected data? Are any of the calls to SetItemText() failing?


        Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

        J Offline
        J Offline
        jgauffin
        wrote on last edited by
        #3

        The while Loop and xml.xxx() works as expected. SetItemText returns 0 (=fail). If I run GetLastError afterwards it returns 0, strange huh?

        1 Reply Last reply
        0
        • J jgauffin

          Hello Im using a CListCtrl and the subitems arent shown when I use the code below. If I put the code in OnInitialUpdate everything works. What's the problem? void CLogAnalyzerView::OnUpdate(CView* /*pSender*/, LPARAM lHint, CObject* /*pHint*/) { CListCtrl& lst = GetListCtrl(); if (lHint == CLogAnalyzerDoc::VIEW_LOADDOC) { CMarkup& xml = GetDocument()->GetXml(); xml.FindElem("/log"); xml.IntoElem(); while (xml.FindElem("session")) { int iItem = 0; while (xml.FindChildElem("entry")) { iItem = lst.InsertItem(LVIF_TEXT, lst.GetItemCount(), xml.GetChildAttrib("stamp"), 0, 0, 0, 0); if (!lst.SetItemText(iItem, 1, xml.GetChildAttrib("prio"))) TRACE("%d\n", GetLastError()); lst.SetItemText(iItem, 2, xml.GetChildAttrib("t")); lst.SetItemText(iItem, 3, "baks"); lst.SetItemText(iItem, 4, xml.GetChildAttrib("group")); lst.SetItemText(iItem, 5, xml.GetChildData()); } } } }

          V Offline
          V Offline
          vcplusplus
          wrote on last edited by
          #4

          I have had much better luck using the LVITEM structure LVITEM lvi; ZeroMemory(&lvi, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.iItem = lst.GetItemCount(); lvi.iSubItem = 0; lvi.pszText = "Test"; lvi.cchTextMax = lstrlen("Test"); INT nInsertPos = m_MyListCtrl.InsertItem(&lvi); ZeroMemory(&lvi, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.iItem = nInsertPos; lvi.iSubItem = 1; lvi.pszText = "Column one test"; lvi.cchTextMax = lstrlen("Column one test"); m_MyListCtrl.SetItem(&lvi);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups