Listview images in LVS_REPORT mode
-
Hello, I am trying to construct a CListView in the LVS_REPORT mode, but I still want an icon at the beginning of each line entry. Is this possible? I can create the listview, and list all the data, but I cannot seem to make the icons appear. I have written the following code: Construction of the listview: int CLPSListView::OnCreate(LPCREATESTRUCT lpCreateStruct) { lpCreateStruct->style |= LVS_REPORT; if (CListView::OnCreate(lpCreateStruct) == -1) return -1; // Give the document a pointer to this view GetDocument()->m_pListView = this; return 0; } In another function where I initialise the data, I create the CImageList, and also the CListCtrlEx, which is a helper class for listviews I found in the MFC Help: CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl(); m_ctlImage.Create(16,16,ILC_COLOR,0,3); HICON PTIcon = theApp.LoadIcon(IDB_CLOSED); ASSERT(PTIcon); m_ctlImage.Add(PTIcon); PTIcon = theApp.LoadIcon(IDB_OPEN); m_ctlImage.Add(PTIcon); ctlList.SetImageList(&m_ctlImage); I create the columns, no problem, and then use the CListCtrlEx method Additem: var = rs.GetFieldValue("Readfld"); ctlList.AddItem(nItem,0,CCrack::strVARIANT(var),0); The last zero refers to the imagelist index. For completeness I attach the AddItem code in CListCtrlEx:- BOOL CListCtrlEx::AddItem(int nItem,int nSubItem,LPCTSTR strItem,int nImageIndex) { LV_ITEM lvItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = nItem; lvItem.iSubItem = nSubItem; lvItem.pszText = (LPTSTR) strItem; if(nImageIndex != -1){ lvItem.mask |= LVIF_IMAGE; lvItem.iImage |= LVIF_IMAGE; } if(nSubItem == 0) return InsertItem(&lvItem); return SetItem(&lvItem); } I would be very grateful to anyone who can suggest how to make the icon appear at the beginning of the line in this Report mode. Thanks, Paul Trimming
-
Hello, I am trying to construct a CListView in the LVS_REPORT mode, but I still want an icon at the beginning of each line entry. Is this possible? I can create the listview, and list all the data, but I cannot seem to make the icons appear. I have written the following code: Construction of the listview: int CLPSListView::OnCreate(LPCREATESTRUCT lpCreateStruct) { lpCreateStruct->style |= LVS_REPORT; if (CListView::OnCreate(lpCreateStruct) == -1) return -1; // Give the document a pointer to this view GetDocument()->m_pListView = this; return 0; } In another function where I initialise the data, I create the CImageList, and also the CListCtrlEx, which is a helper class for listviews I found in the MFC Help: CListCtrlEx& ctlList = (CListCtrlEx&) GetListCtrl(); m_ctlImage.Create(16,16,ILC_COLOR,0,3); HICON PTIcon = theApp.LoadIcon(IDB_CLOSED); ASSERT(PTIcon); m_ctlImage.Add(PTIcon); PTIcon = theApp.LoadIcon(IDB_OPEN); m_ctlImage.Add(PTIcon); ctlList.SetImageList(&m_ctlImage); I create the columns, no problem, and then use the CListCtrlEx method Additem: var = rs.GetFieldValue("Readfld"); ctlList.AddItem(nItem,0,CCrack::strVARIANT(var),0); The last zero refers to the imagelist index. For completeness I attach the AddItem code in CListCtrlEx:- BOOL CListCtrlEx::AddItem(int nItem,int nSubItem,LPCTSTR strItem,int nImageIndex) { LV_ITEM lvItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = nItem; lvItem.iSubItem = nSubItem; lvItem.pszText = (LPTSTR) strItem; if(nImageIndex != -1){ lvItem.mask |= LVIF_IMAGE; lvItem.iImage |= LVIF_IMAGE; } if(nSubItem == 0) return InsertItem(&lvItem); return SetItem(&lvItem); } I would be very grateful to anyone who can suggest how to make the icon appear at the beginning of the line in this Report mode. Thanks, Paul Trimming
ListView_SetImageList(hwnd, ImgListHandle, LVSIL_SMALL);
-
ListView_SetImageList(hwnd, ImgListHandle, LVSIL_SMALL);
Thanks for your reply, Roman. By adding LVSIL_SMALL (ctlList.SetImageList(&m_ctlImage1,LVSIL_SMALL);) I got the listview to display the first loaded icon. (In the imagelist there are two different icons.) But the strange thing is that I have to put -1 in the actual line where I add the listitem, as follows: ctlList.AddItem(nItem,NULL,CCrack::strVARIANT(var),-1); If I put anything else, the icon disappears!! As I have two icons in the imagelist, I should have thought I should put 0 or 1 in, and I should be able to vary which icon appears. (The -1 entry is the default.) I would be most grateful for help as to why this is happening. Thanks, trimtrom