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. CImageList and CListCtrl

CImageList and CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
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.
  • W Offline
    W Offline
    Wim Engberts
    wrote on last edited by
    #1

    Hi everybody, I have a list control in my dialog, in which I display a numbr of items. The program can toggle between two states: one where only recent items are shown and one where also history is shown. In the latter case, I want to show icons in front of each row, indicating whether an item is recent or not. In itself, this all works: I add a CImageCtrl to the listbox, with the relevant icons. When the program switches back to only recent items, I do not want to show the icons anymore, so I remove the CImageList using CListCtrl::SetImageList (NULL, 0); In itself this works: no icons are shown anymore. However, the item in the first column is now still moved to the right to make room for a possible icon. How do I tell the CListCtrl that also the text in the first column must be displayed at the most left-hand side, rather than moving the items to the right? Please help!! Thanks in advance, William

    D 1 Reply Last reply
    0
    • W Wim Engberts

      Hi everybody, I have a list control in my dialog, in which I display a numbr of items. The program can toggle between two states: one where only recent items are shown and one where also history is shown. In the latter case, I want to show icons in front of each row, indicating whether an item is recent or not. In itself, this all works: I add a CImageCtrl to the listbox, with the relevant icons. When the program switches back to only recent items, I do not want to show the icons anymore, so I remove the CImageList using CListCtrl::SetImageList (NULL, 0); In itself this works: no icons are shown anymore. However, the item in the first column is now still moved to the right to make room for a possible icon. How do I tell the CListCtrl that also the text in the first column must be displayed at the most left-hand side, rather than moving the items to the right? Please help!! Thanks in advance, William

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

      Engberts wrote:

      When the program switches back to only recent items...

      How are you adding items at this point?


      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

      "Judge not by the eye but by the heart." - Native American Proverb

      W 1 Reply Last reply
      0
      • D David Crow

        Engberts wrote:

        When the program switches back to only recent items...

        How are you adding items at this point?


        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

        "Judge not by the eye but by the heart." - Native American Proverb

        W Offline
        W Offline
        Wim Engberts
        wrote on last edited by
        #3

        I Clear all the items (using DeleteAllItems), delete all the columns (using n = GetHeaderCtrl()->GetItemCount(); while (n-- > 0) DeleteColumn (0) Then I clear the image list (using SetImageList (NULL, 0). Then I re-create all the columns (I do this, because I use a separate empty column for the icon, which is either or not included when re-creating the columns depending on whether or not I want to show icons) and then I add the new set of items (using InsertItem for the first columns and SetItem for subsequent columns of the same row) William

        D 1 Reply Last reply
        0
        • W Wim Engberts

          I Clear all the items (using DeleteAllItems), delete all the columns (using n = GetHeaderCtrl()->GetItemCount(); while (n-- > 0) DeleteColumn (0) Then I clear the image list (using SetImageList (NULL, 0). Then I re-create all the columns (I do this, because I use a separate empty column for the icon, which is either or not included when re-creating the columns depending on whether or not I want to show icons) and then I add the new set of items (using InsertItem for the first columns and SetItem for subsequent columns of the same row) William

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

          But what code do you have in place for adding items to the control? Is it in any way referencing an image (or image list)?


          "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

          "Judge not by the eye but by the heart." - Native American Proverb

          W 1 Reply Last reply
          0
          • D David Crow

            But what code do you have in place for adding items to the control? Is it in any way referencing an image (or image list)?


            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

            "Judge not by the eye but by the heart." - Native American Proverb

            W Offline
            W Offline
            Wim Engberts
            wrote on last edited by
            #5

            I am using a derived class "CListCtrlEx", which has the following code for adding a row: BOOL CListCtrlEx::AddLine(char *Elements, UINT Id, int iImage) { LVITEM Item; register int i = 0; register int j = 0; int subItem = 0; int r = 1; int k = 0; char szItem[256]; memset (&Item, '\0', sizeof (LVITEM)); Item.mask = LVIF_TEXT|LVIF_PARAM; Item.iItem = m_ItemId++; Item.lParam = Id; while (r && Elements[k] != '\0') { j = k; i = 0; while (Elements[j] != '\0'&& Elements[j] != '\t') { if (i < 250) szItem[i++] = Elements[j]; j++; } szItem[i] = '\0'; Item.iSubItem = subItem++; Item.pszText = &szItem[0]; if (k == 0) { if (iImage != -1) { Item.iImage = iImage; Item.mask |= LVIF_IMAGE; } if (InsertItem (&Item) == -1) r = 0; else r = 1; } else if ((r = SetItem (&Item)) != 0) r = 1; if (Elements[k=j] == '\t') k++; Item.mask = LVIF_TEXT; } return r; } I present this routinew with a character array in which the elements (columns) are separated by tabs. As you can see, the routine only adds an image when the parameter "iImage" does not equal -1, which it does when I populate the contgrol with only recent items where I do not want to see icons. Again: The icons do not show, but the space for the icons remains reserved, which leads to the situation that, on first appearance, the left elements are completely left aligned, but after showing the history items, they always show shifted to the right. William

            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