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