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. Why doesn't this work?

Why doesn't this work?

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingtutorialquestion
3 Posts 2 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.
  • Z Offline
    Z Offline
    Zero_divide_1
    wrote on last edited by
    #1

    I have the following code adding to a CListCtl on a dialog box named m_cList, but for some reason the first element I add doesn't show up: LRESULT CRTFParseTest1Dlg::OnCreateListGroup(WPARAM wParam, LPARAM lParam) { CStringArray sa, sa1; CString sFormat; for(int a(0); a < 3; a++) { sFormat.Format("Column %d", a); sa.Add(sFormat); } InsertColumns(sa); sa.RemoveAll(); sa.Add("Item"); for(int b(0); b < 5; b++) { sFormat.Format("Group %d", b); AddListGroup(b, sFormat); for(int b_0(0); b_0 < 2; b_0++) { sa[0].Format("%d:%d", b,b_0); AddItemToGroup(b_0, sa, b); } } return 0; } LRESULT CRTFParseTest1Dlg::AddListGroup(int id, CString sTitle) { USES_CONVERSION; if(!m_cList.IsGroupViewEnabled()) { if(m_cList.EnableGroupView(TRUE) == -1 || !m_cList.IsGroupViewEnabled()) { TRACE("==>CParseTest1Dlg::AddListGroup { Could not enable list grouping }\n"); return -1; } } LVGROUP lvg; ZeroMemory(&lvg, sizeof(lvg)); lvg.cbSize = sizeof(LVGROUP); lvg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE; lvg.pszHeader = A2W(sTitle); lvg.cchHeader = sTitle.GetLength(); lvg.iGroupId = id; lvg.stateMask = LVGS_NORMAL; lvg.state = LVGS_NORMAL; return m_cList.InsertGroup(-1, &lvg); } LRESULT CRTFParseTest1Dlg::AddItemToGroup(int id, CStringArray &sColumnText, int iGroupId/* = -1*/) { int iRes = m_cList.InsertItem(id, sColumnText[0]); if(iRes >= 0) { iRes = TRUE; for(int i(1); i < sColumnText.GetSize() && iRes != FALSE; i++) { iRes = m_cList.SetItemText(id, i, sColumnText[i]); } if(iRes != FALSE && iGroupId != -1) { LVITEM lvi; lvi.mask = LVIF_GROUPID; lvi.iGroupId = iGroupId; lvi.iItem = i; iRes = m_cList.SetItem(&lvi); } } return iRes; } bool CRTFParseTest1Dlg::InsertColumns(CStringArray &sColumnTitles) { int iRes(0); for(int i(0); i < sColumnTitles.GetSize() && iRes!=-1; i++) { iRes = m_cList.InsertColumn(i, sColumnTitles[i], LVCFMT_LEFT, 100); } return (iRes != -1); } Any idea how to make it work?

    2 1 Reply Last reply
    0
    • Z Zero_divide_1

      I have the following code adding to a CListCtl on a dialog box named m_cList, but for some reason the first element I add doesn't show up: LRESULT CRTFParseTest1Dlg::OnCreateListGroup(WPARAM wParam, LPARAM lParam) { CStringArray sa, sa1; CString sFormat; for(int a(0); a < 3; a++) { sFormat.Format("Column %d", a); sa.Add(sFormat); } InsertColumns(sa); sa.RemoveAll(); sa.Add("Item"); for(int b(0); b < 5; b++) { sFormat.Format("Group %d", b); AddListGroup(b, sFormat); for(int b_0(0); b_0 < 2; b_0++) { sa[0].Format("%d:%d", b,b_0); AddItemToGroup(b_0, sa, b); } } return 0; } LRESULT CRTFParseTest1Dlg::AddListGroup(int id, CString sTitle) { USES_CONVERSION; if(!m_cList.IsGroupViewEnabled()) { if(m_cList.EnableGroupView(TRUE) == -1 || !m_cList.IsGroupViewEnabled()) { TRACE("==>CParseTest1Dlg::AddListGroup { Could not enable list grouping }\n"); return -1; } } LVGROUP lvg; ZeroMemory(&lvg, sizeof(lvg)); lvg.cbSize = sizeof(LVGROUP); lvg.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE; lvg.pszHeader = A2W(sTitle); lvg.cchHeader = sTitle.GetLength(); lvg.iGroupId = id; lvg.stateMask = LVGS_NORMAL; lvg.state = LVGS_NORMAL; return m_cList.InsertGroup(-1, &lvg); } LRESULT CRTFParseTest1Dlg::AddItemToGroup(int id, CStringArray &sColumnText, int iGroupId/* = -1*/) { int iRes = m_cList.InsertItem(id, sColumnText[0]); if(iRes >= 0) { iRes = TRUE; for(int i(1); i < sColumnText.GetSize() && iRes != FALSE; i++) { iRes = m_cList.SetItemText(id, i, sColumnText[i]); } if(iRes != FALSE && iGroupId != -1) { LVITEM lvi; lvi.mask = LVIF_GROUPID; lvi.iGroupId = iGroupId; lvi.iItem = i; iRes = m_cList.SetItem(&lvi); } } return iRes; } bool CRTFParseTest1Dlg::InsertColumns(CStringArray &sColumnTitles) { int iRes(0); for(int i(0); i < sColumnTitles.GetSize() && iRes!=-1; i++) { iRes = m_cList.InsertColumn(i, sColumnTitles[i], LVCFMT_LEFT, 100); } return (iRes != -1); } Any idea how to make it work?

      2 Offline
      2 Offline
      224917
      wrote on last edited by
      #2

      your code displays 10 elements and is working. starting from 0.0 to 4.1 . Which is the exact string you feel is missing as per the code.


      suhredayan
      There is no spoon.

      Z 1 Reply Last reply
      0
      • 2 224917

        your code displays 10 elements and is working. starting from 0.0 to 4.1 . Which is the exact string you feel is missing as per the code.


        suhredayan
        There is no spoon.

        Z Offline
        Z Offline
        Zero_divide_1
        wrote on last edited by
        #3

        The code to create them does work, but in the list the groups don't have the right elements in them. Here is what I get in my list control: Group 0 -0:1 Group 1 -0:0 <--This should be in group 0 -1:1 Group 2 -1:0 <--This should be in group 1 -2:1 Group 3 -2:0 <--This should be in group 2 -3:1 Group 4 -3:0 <--This should be in group 3 -4:1 <--Where did 4:0 go? It doesn't show up in the list. The problem is the first element in each group shows up in the preceeding group, which is probably why 4:0 does not show up. I can't seem to figure out why this happens and how to fix it. Got any ideas?

        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