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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. listview items dont appear

listview items dont appear

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 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
    Trucker
    wrote on last edited by
    #1

    Hello, In my MFC application, I am having a problem with my listview's items. They don't show. It looks like they are there because when they load the scroll bars appear. The following code is OnCreate() where I Initialize the listView: int CTopRightView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; SetWindowLong(GetListCtrl().m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|LVS_LIST); COLORREF c = PALETTERGB(200, 70, 130); GetListCtrl().SetBkColor(c); //creating image list for listview smallImageList.Create(16,16,false,1,0); //adding icon to image list HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON3)); smallImageList.Add(hIcon); GetListCtrl().SetImageList(&smallImageList, LVSIL_SMALL); return 0; } And this piece of code adds an item to the listview: LV_ITEM lvItem; ::memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_STATE; lvItem.state = 0; lvItem.stateMask = 0; lvItem.pszText = GetNTS(GetDocument()->fileName); lvItem.iItem = GetDocument()->fileCount; lvItem.iImage = 0; GetListCtrl().InsertItem(&lvItem); Anybody might know what I am doing wrong?:doh: TraileR ParK LifE 4Ever

    D 1 Reply Last reply
    0
    • T Trucker

      Hello, In my MFC application, I am having a problem with my listview's items. They don't show. It looks like they are there because when they load the scroll bars appear. The following code is OnCreate() where I Initialize the listView: int CTopRightView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; SetWindowLong(GetListCtrl().m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|LVS_LIST); COLORREF c = PALETTERGB(200, 70, 130); GetListCtrl().SetBkColor(c); //creating image list for listview smallImageList.Create(16,16,false,1,0); //adding icon to image list HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON3)); smallImageList.Add(hIcon); GetListCtrl().SetImageList(&smallImageList, LVSIL_SMALL); return 0; } And this piece of code adds an item to the listview: LV_ITEM lvItem; ::memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_STATE; lvItem.state = 0; lvItem.stateMask = 0; lvItem.pszText = GetNTS(GetDocument()->fileName); lvItem.iItem = GetDocument()->fileCount; lvItem.iImage = 0; GetListCtrl().InsertItem(&lvItem); Anybody might know what I am doing wrong?:doh: TraileR ParK LifE 4Ever

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      /* Trucker */ wrote: SetWindowLong(GetListCtrl().m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|LVS_LIST); There's a much simpler way to do this, and you only have to do it once:

      BOOL CTopRightView::PreCreateWindow(CREATESTRUCT& cs)
      {
      cs.style |= LVS_LIST;
      return CListView::PreCreateWindow(cs);
      }

      What does InsertItem() return?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      T 1 Reply Last reply
      0
      • D David Crow

        /* Trucker */ wrote: SetWindowLong(GetListCtrl().m_hWnd, GWL_STYLE, WS_VISIBLE|WS_CHILD|LVS_LIST); There's a much simpler way to do this, and you only have to do it once:

        BOOL CTopRightView::PreCreateWindow(CREATESTRUCT& cs)
        {
        cs.style |= LVS_LIST;
        return CListView::PreCreateWindow(cs);
        }

        What does InsertItem() return?


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

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

        Hi David, InsertItem() returns a positive value if successful or -1 otherwise. TraileR ParK LifE 4Ever

        D 1 Reply Last reply
        0
        • T Trucker

          Hi David, InsertItem() returns a positive value if successful or -1 otherwise. TraileR ParK LifE 4Ever

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          So is it returning -1 in this case, or is it returning a positive value yet the items still do not show up?


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          T 1 Reply Last reply
          0
          • D David Crow

            So is it returning -1 in this case, or is it returning a positive value yet the items still do not show up?


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            T Offline
            T Offline
            Trucker
            wrote on last edited by
            #5

            it is returning a positive value but the items still do not show up. TraileR ParK LifE 4Ever

            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