Can some one please tell me how to insert items into a friggin CListCtrl
-
This method does not work:
// Insert item for col 0
lvi.mask = LVIF_TEXT;
lvi.pszText = "one";
m_ListCtrl.InsertItem(&lvi);
// Insert subitem for col 1
lvi.pszText = "two";
lvi.iSubItem = 1;
m_ListCtrl.InsertItem(&lvi);This method does not work:
for (int nI = 0; nI < m\_strarrayOtherImgFiles.GetCount(); nI++) { pOtherImgsList->SetItemText(nI, 0, m\_strarrayOtherImgFiles.GetAt(nI)); }
Nothing seems to work.
-
This method does not work:
// Insert item for col 0
lvi.mask = LVIF_TEXT;
lvi.pszText = "one";
m_ListCtrl.InsertItem(&lvi);
// Insert subitem for col 1
lvi.pszText = "two";
lvi.iSubItem = 1;
m_ListCtrl.InsertItem(&lvi);This method does not work:
for (int nI = 0; nI < m\_strarrayOtherImgFiles.GetCount(); nI++) { pOtherImgsList->SetItemText(nI, 0, m\_strarrayOtherImgFiles.GetAt(nI)); }
Nothing seems to work.
Hello, First, see the topic - 'How to ask Questions' in this forum. Second, you are missing lvi.iItem I think. Try adding this and see.
// Insert item for col 0
lvi.mask = LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = "one";
m_ListCtrl.InsertItem(&lvi);
// Insert subitem for col 1
lvi.pszText = "two";
lvi.iSubItem = 1;
m_ListCtrl.InsertItem(&lvi);Regards, A. Gopinath.
-
This method does not work:
// Insert item for col 0
lvi.mask = LVIF_TEXT;
lvi.pszText = "one";
m_ListCtrl.InsertItem(&lvi);
// Insert subitem for col 1
lvi.pszText = "two";
lvi.iSubItem = 1;
m_ListCtrl.InsertItem(&lvi);This method does not work:
for (int nI = 0; nI < m\_strarrayOtherImgFiles.GetCount(); nI++) { pOtherImgsList->SetItemText(nI, 0, m\_strarrayOtherImgFiles.GetAt(nI)); }
Nothing seems to work.
You could always try reading the documentation[^], or finding one of the many articles, such as: Using the List Control[^].
-
You could always try reading the documentation[^], or finding one of the many articles, such as: Using the List Control[^].
I have been reading the documentation - where else do you think I obtained those methods that I have been trying. This is what I have tried precisely. And function
int InsertItem(
int nItem,
LPCTSTR lpszItem,as described here (http://msdn.microsoft.com/en-us/library/8b9s12fc.aspx[^]), DOES NOT WORK The function does nothing. WHY? Can you only add items to a CListCtrl via
int InsertItem(
const LVITEM* pItem
);and the function that I have been using is in fact defunct?
**void CImageDialog::DDX_List(CDataExchange* pDX, UINT uListCtrlID, CStringArray& rarrayOtherImgFiles)
{
CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(uListCtrlID);
int nI = 0;
CString strItem;ASSERT\_VALID(pListCtrl); if (pDX->m\_bSaveAndValidate) { m\_arrayOtherImageFiles.RemoveAll(); for (nI = 0; nI < pListCtrl->GetItemCount(); nI++) { strItem = pListCtrl->GetItemText(nI, 0); m\_arrayOtherImageFiles.Add(strItem); } } else { pListCtrl->DeleteAllItems(); for (nI = m\_arrayOtherImageFiles.GetCount() - 1; nI >= 0; nI--) { pListCtrl->InsertItem(1, m\_arrayOtherImageFiles.GetAt(nI)); } }
}**
void CImageDialog::DoDataExchange(CDataExchange* pDX)
{
CMyDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_HEADER_IMG, m_strHeaderImageFile);
DDX_Text(pDX, IDC_EDIT_NAV_IMG1, m_strNavImg1File);
DDX_Text(pDX, IDC_EDIT_NAV_IMG2, m_strNavImg2File);
DDX_Text(pDX, IDC_EDIT_OTHER_IMG_FILES, m_strOtherImgFiles);
DDX_List(pDX, IDC_LIST_OTHER_IMG_FILES, m_arrayOtherImageFiles);
} -
I have been reading the documentation - where else do you think I obtained those methods that I have been trying. This is what I have tried precisely. And function
int InsertItem(
int nItem,
LPCTSTR lpszItem,as described here (http://msdn.microsoft.com/en-us/library/8b9s12fc.aspx[^]), DOES NOT WORK The function does nothing. WHY? Can you only add items to a CListCtrl via
int InsertItem(
const LVITEM* pItem
);and the function that I have been using is in fact defunct?
**void CImageDialog::DDX_List(CDataExchange* pDX, UINT uListCtrlID, CStringArray& rarrayOtherImgFiles)
{
CListCtrl* pListCtrl = (CListCtrl*)GetDlgItem(uListCtrlID);
int nI = 0;
CString strItem;ASSERT\_VALID(pListCtrl); if (pDX->m\_bSaveAndValidate) { m\_arrayOtherImageFiles.RemoveAll(); for (nI = 0; nI < pListCtrl->GetItemCount(); nI++) { strItem = pListCtrl->GetItemText(nI, 0); m\_arrayOtherImageFiles.Add(strItem); } } else { pListCtrl->DeleteAllItems(); for (nI = m\_arrayOtherImageFiles.GetCount() - 1; nI >= 0; nI--) { pListCtrl->InsertItem(1, m\_arrayOtherImageFiles.GetAt(nI)); } }
}**
void CImageDialog::DoDataExchange(CDataExchange* pDX)
{
CMyDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_HEADER_IMG, m_strHeaderImageFile);
DDX_Text(pDX, IDC_EDIT_NAV_IMG1, m_strNavImg1File);
DDX_Text(pDX, IDC_EDIT_NAV_IMG2, m_strNavImg2File);
DDX_Text(pDX, IDC_EDIT_OTHER_IMG_FILES, m_strOtherImgFiles);
DDX_List(pDX, IDC_LIST_OTHER_IMG_FILES, m_arrayOtherImageFiles);
}Of course the function works, it is used in List controls all over the world. It is more likely that your code is doing something wrong. For a start you are not checking the return code to see whether it succeeded or not, and if not, why. What is the current value of the index
nI
, and what is being returned by the call tom_arrayOtherImageFiles.GetAt(nI)
? Use your debugger to trace through your code to diagnose the problem.