CListCtrl problem
-
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()); } } } }
-
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()); } } } }
Does the
while
loop get executed as expected? Do thexml.Getxxx()
calls return the expected data? Are any of the calls toSetItemText()
failing?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Does the
while
loop get executed as expected? Do thexml.Getxxx()
calls return the expected data? Are any of the calls toSetItemText()
failing?
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
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()); } } } }
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);