Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Listview images in LVS_REPORT mode

Listview images in LVS_REPORT mode

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++databasetutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    trimtrom
    wrote on last edited by
    #1

    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

    R 1 Reply Last reply
    0
    • T trimtrom

      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

      R Offline
      R Offline
      Roman Fadeyev
      wrote on last edited by
      #2

      ListView_SetImageList(hwnd, ImgListHandle, LVSIL_SMALL);

      T 1 Reply Last reply
      0
      • R Roman Fadeyev

        ListView_SetImageList(hwnd, ImgListHandle, LVSIL_SMALL);

        T Offline
        T Offline
        trimtrom
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups