CListCtrl not showing all loaded items?
-
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
-
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
Hi Trey, Very weird! Maybe there's a bug in the initializing function... Can you provide some code? Paolo.
-
Hi Trey, Very weird! Maybe there's a bug in the initializing function... Can you provide some code? Paolo.
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); } }
-
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); } }
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. -
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