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 not showing all loaded items?

CListCtrl not showing all loaded items?

Scheduled Pinned Locked Moved C / C++ / MFC
5 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.
  • T Offline
    T Offline
    trey
    wrote on last edited by
    #1

    I'm having a weird problem where my CListCtrl doesn't show all the items that I load in it. I'm using a function to load the control initially using LVITEM with InsertItem() followed by SetItem() for all subitems, and this part works. However, as the program is running I have to update the listctrl so I call ResetContent() to clear the rows and then call the initialize function mentioned above to reload everything. The problem is that when I do this, only the first item shows up in every row. Usually the subitems are blank in most of the rows. Some rows do show up correctly, but this is only on a few rows. When I say correctly I mean all subitems are shown with the main row item. Can someone help me with this? Thanks in advance, --Trey

    P T 2 Replies Last reply
    0
    • T trey

      I'm having a weird problem where my CListCtrl doesn't show all the items that I load in it. I'm using a function to load the control initially using LVITEM with InsertItem() followed by SetItem() for all subitems, and this part works. However, as the program is running I have to update the listctrl so I call ResetContent() to clear the rows and then call the initialize function mentioned above to reload everything. The problem is that when I do this, only the first item shows up in every row. Usually the subitems are blank in most of the rows. Some rows do show up correctly, but this is only on a few rows. When I say correctly I mean all subitems are shown with the main row item. Can someone help me with this? Thanks in advance, --Trey

      P Offline
      P Offline
      Paolo Messina
      wrote on last edited by
      #2

      Hi Trey, Very weird! Maybe there's a bug in the initializing function... Can you provide some code? Paolo.

      T 1 Reply Last reply
      0
      • P Paolo Messina

        Hi Trey, Very weird! Maybe there's a bug in the initializing function... Can you provide some code? Paolo.

        T Offline
        T Offline
        trey
        wrote on last edited by
        #3

        Ok, I have a database objectthat has two vectors of CStrings. I update the database and then call LoadListData(). Like I said before this is weird! Here is the code to initialize the data: void CMyDlg::LoadListData(CDatabase* database) { // Delete the current contents m_cListCtrl.DeleteAllItems(); // Use the LV_ITEM structure to insert the items LVITEM lvi; lvi.mask = LVIF_TEXT; CString strItem; int numberOfAddresses = database->GetAddressCount(); for (int i = 0; i < numberOfAddresses; i++) { //* CAddress* a = database->GetAddress(i); // Filter if necessary if(m_bFilterOn && a->m_csCategory != m_csFilterCategory) continue; // Insert the first item - First Name lvi.iItem = i; lvi.iSubItem = 0; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csFName); m_cListCtrl.InsertItem(&lvi); // Set subitem 1 - Last Name lvi.iSubItem = 1; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csLName); m_cListCtrl.SetItem(&lvi); // Set subitem 2 - Company lvi.iSubItem = 2; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCompany); m_cListCtrl.SetItem(&lvi); // Set subitem 3 - Address 1 lvi.iSubItem = 3; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress1); m_cListCtrl.SetItem(&lvi); // Set subitem 4 - Address 2 lvi.iSubItem = 4; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress2); m_cListCtrl.SetItem(&lvi); // Set subitem 5 - City lvi.iSubItem = 5; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCity); m_cListCtrl.SetItem(&lvi); // Set subitem 6 - State lvi.iSubItem = 6; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csState); m_cListCtrl.SetItem(&lvi); // Set subitem 7 - Zipcode lvi.iSubItem = 7; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csZipcode); } }

        P 1 Reply Last reply
        0
        • T trey

          Ok, I have a database objectthat has two vectors of CStrings. I update the database and then call LoadListData(). Like I said before this is weird! Here is the code to initialize the data: void CMyDlg::LoadListData(CDatabase* database) { // Delete the current contents m_cListCtrl.DeleteAllItems(); // Use the LV_ITEM structure to insert the items LVITEM lvi; lvi.mask = LVIF_TEXT; CString strItem; int numberOfAddresses = database->GetAddressCount(); for (int i = 0; i < numberOfAddresses; i++) { //* CAddress* a = database->GetAddress(i); // Filter if necessary if(m_bFilterOn && a->m_csCategory != m_csFilterCategory) continue; // Insert the first item - First Name lvi.iItem = i; lvi.iSubItem = 0; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csFName); m_cListCtrl.InsertItem(&lvi); // Set subitem 1 - Last Name lvi.iSubItem = 1; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csLName); m_cListCtrl.SetItem(&lvi); // Set subitem 2 - Company lvi.iSubItem = 2; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCompany); m_cListCtrl.SetItem(&lvi); // Set subitem 3 - Address 1 lvi.iSubItem = 3; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress1); m_cListCtrl.SetItem(&lvi); // Set subitem 4 - Address 2 lvi.iSubItem = 4; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csAddress2); m_cListCtrl.SetItem(&lvi); // Set subitem 5 - City lvi.iSubItem = 5; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csCity); m_cListCtrl.SetItem(&lvi); // Set subitem 6 - State lvi.iSubItem = 6; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csState); m_cListCtrl.SetItem(&lvi); // Set subitem 7 - Zipcode lvi.iSubItem = 7; lvi.pszText = (LPTSTR)(LPCTSTR)(a->m_csZipcode); } }

          P Offline
          P Offline
          Paolo Messina
          wrote on last edited by
          #4

          Well, what I can see is: it lacks the last SetItem. For ther rest it seems OK. Try doing ASSERTs on the return value of each SetItem and go with the Debug version. Also, you may try to add: ZeroMemory(&lvi, sizeof(LVITEM)); just after the definition. I found that sometimes this could help... or does nothing :) Paolo.

          1 Reply Last reply
          0
          • T trey

            I'm having a weird problem where my CListCtrl doesn't show all the items that I load in it. I'm using a function to load the control initially using LVITEM with InsertItem() followed by SetItem() for all subitems, and this part works. However, as the program is running I have to update the listctrl so I call ResetContent() to clear the rows and then call the initialize function mentioned above to reload everything. The problem is that when I do this, only the first item shows up in every row. Usually the subitems are blank in most of the rows. Some rows do show up correctly, but this is only on a few rows. When I say correctly I mean all subitems are shown with the main row item. Can someone help me with this? Thanks in advance, --Trey

            T Offline
            T Offline
            trey
            wrote on last edited by
            #5

            I'm still having problems. Can anyone help me please? I'm only using the report mode and I have added the columns correctly. Like I originally stated, I'm able to load the listctrl successfully once.

            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