CListView problem
Jeff Rucker -- jrucker@ssccorp.com Tuesday, March 11, 1997 Environment : Win95, VC++ 4.1 I'm having a problem with my list view (report mode) where only the first column is showing up. All the api calls return OK, I just don't see anything. I've had CListCtrl code working other places, just not as CListView. Am I doing something wrong? TIA ///////////////////////////////////////////////////////////////////////////// // CSummaryView message handlers void CSummaryView::OnInitialUpdate() { CListView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class CListCtrl& cList = GetListCtrl(); cList.ModifyStyle(LVS_LIST | LVS_ICON,LVS_REPORT); for (int n=0;n<3;n++) { cList.DeleteColumn(0); } cList.InsertColumn(0,"PDE Code",LVCFMT_LEFT,100,-1); cList.InsertColumn(1,"Parameters",LVCFMT_LEFT,100,-1); cList.InsertColumn(2,"Comment",LVCFMT_LEFT,100,-1); } #pragma warning(disable:4100) void CSummaryView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { CListCtrl& cList = GetListCtrl(); CPDEDoc *pDoc = (CPDEDoc *)GetDocument(); CString strCode,strComment; CParams cParams; cList.DeleteAllItems(); int nIndex = 0,nItemIndex,nParamIndex; while (pDoc->GetNextCode(nIndex++,strCode,strComment,cParams)) { if (strCode.IsEmpty()) continue; //nItemIndex = cList.InsertItem(0,strCode); nItemIndex = cList.InsertItem(LVIF_TEXT, 0,strCode, 0, 0, 0, 0); CString strValue,strTemp; strValue = cParams.GetParam(0); nParamIndex = 1; while (1) { strTemp = cParams.GetParam(nParamIndex++); if (strTemp.IsEmpty()) break; strValue += "," + strTemp; } cList.SetItemText(nItemIndex,1,strValue); cList.SetItemText(nItemIndex,2,strComment); cList.Update(nItemIndex); } return; } #pragma warning(default:4100) ------------------------------------- Jeff Rucker Software Systems Consulting 13641 Mercado Drive Del Mar, CA 92014 (voice)619-481-3439 (fax)619-259-5554 jrucker@ssccorp.com -------------------------------------
Paul Gerhart -- pgerhart@voicenet.com Friday, March 14, 1997 Jeff Rucker wrote: > > Environment : Win95, VC++ 4.1 > > I'm having a problem with my list view (report mode) where only the first > column is showing up. All the api calls return OK, I just don't see > anything. I've had CListCtrl code working other places, just not as > CListView. Am I doing something wrong? > > TIA > > ///////////////////////////////////////////////////////////////////////////// > // CSummaryView message handlers > > void CSummaryView::OnInitialUpdate() > { > CListView::OnInitialUpdate(); > > // TODO: Add your specialized code here and/or call the base class > CListCtrl& cList = GetListCtrl(); > cList.ModifyStyle(LVS_LIST | LVS_ICON,LVS_REPORT); > for (int n=0;n<3;n++) > { > cList.DeleteColumn(0); > } > cList.InsertColumn(0,"PDE Code",LVCFMT_LEFT,100,-1); > cList.InsertColumn(1,"Parameters",LVCFMT_LEFT,100,-1); > cList.InsertColumn(2,"Comment",LVCFMT_LEFT,100,-1); > } > I did not study the other code (below here in your original post) but as regard the above... Instead of your for loop I would do it via a single call cList.SetItemCount(0); I would approach this by simply creating an LV_COLUMN lvcol; structure and set the mask, format styles et al like this lvcol.mask = per your desire; //mask lvcol.fmt = per your desire; //format lvcol.cx = per your desire; //width lvcol.pszText = per your desire; //text lvcol.iSubItem = n; // cycle n from 0 to 2 and use the cList.InsertColumn( n, &lvcol ); // cycle n from 0 to 2 form of the call in a for loop with a switcj/case (or similar). Mike B's book is very thorough on this topic, that is the way he described it, I followed his approach, it works. My guess is that the lvcol.subitem is not being handled correctly with how you are doing your call. Hope this helps. > #pragma warning(disable:4100) > void CSummaryView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) > { > CListCtrl& cList = GetListCtrl(); > CPDEDoc *pDoc = (CPDEDoc *)GetDocument(); > CString strCode,strComment; > CParams cParams; > > cList.DeleteAllItems(); > int nIndex = 0,nItemIndex,nParamIndex; > while (pDoc->GetNextCode(nIndex++,strCode,strComment,cParams)) > { > if (strCode.IsEmpty()) > continue; > //nItemIndex = cList.InsertItem(0,strCode); > nItemIndex = cList.InsertItem(LVIF_TEXT, 0,strCode, 0, 0, 0, 0); > CString strValue,strTemp; > strValue = cParams.GetParam(0); > nParamIndex = 1; > while (1) > { > strTemp = cParams.GetParam(nParamIndex++); > if (strTemp.IsEmpty()) > break; > strValue += "," + strTemp; > } > cList.SetItemText(nItemIndex,1,strValue); > cList.SetItemText(nItemIndex,2,strComment); > cList.Update(nItemIndex); > } > return; > } > #pragma warning(default:4100) > > ------------------------------------- > Jeff Rucker > Software Systems Consulting > 13641 Mercado Drive > Del Mar, CA 92014 > (voice)619-481-3439 (fax)619-259-5554 > jrucker@ssccorp.com > ------------------------------------- -- ######################### # Paul Gerhart # # pgerhart@voicenet.com # #########################
Become an MFC-L member | Вернуться в корень Архива |