• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

CComboBoxEx, CImageList, missing images


I have CComboBoxEx with images stored in CImageList. In CImageList I have one image for one indicated state of combobox item - each combobox item should have one and only image all the time the comboboxex is displayed.

But when I SW_SHOW this comboboxex (normally it is hidden, I show it just in case it is needed - I empty it, fill with items, show, after selection hide), I see all images OK but the one tied to selected item. Selected item has no image at all - neither in drop down list, nor in edit portion of comboboxex.

Remark: when I tried to add CBEIF_SELECTEDIMAGE and fill in cbi.iSelectedImage member, it had the same behavior.

Thanks - any help would be welcome.

Code for adding items:

     CComboBoxEx*     pCtrl = (CComboBoxEx*)pWnd;
     COMBOBOXEXITEM     cbi;

     for (int i = 0; i < arrCislo.GetSize(); i++)
          sItem = arrCislo.GetAt(i).m_sText;

          cbi.iItem = i;
          cbi.pszText = (LPTSTR)(LPCTSTR)sItem;
          cbi.cchTextMax = sItem.GetLength();
          cbi.iImage = arrCislo.GetAt(i).m_nTypCD;
          // cbi.iSelectedImage = 1;

          nIndex = pCtrl->InsertItem(&cbi);
          if (nIndex == LB_ERR) break;          

          pMstCislo = new tstMstCislo;
          *pMstCislo = arrCislo.GetAt(i);
          pCtrl->SetItemDataPtr(nIndex, pMstCislo);
Martin Bodlák
Martin Bodlák
  • 3
  • 3
1 Solution
Roshan DavisCommented:
I think gb_imgCisDomTyp have only one image.
The image index starts from 0 (Zero).

Please quote the code, adding images to the list..

Martin BodlákAuthor Commented:
All those variables are in library together with manipulation functions. I call library function with CComboBoxEx&, which is filled with items and images (see above) and returned.

In ImageList there are three images. In ComboBoxEx, only one image is not shown: the one in selected item. All other images are OK (all kinds of images are seen, if their item is not selected).

static     CBitmap               gb_bmpCisDom_X;          // chybna hodnota
static     CBitmap               gb_bmpCisDom_0;          // neurceno
static     CBitmap               gb_bmpCisDom_P;          // cislo popisne
static     CBitmap               gb_bmpCisDom_E;          // cislo evidencni

static     CImageList          gb_imgCisDomTyp;

     gb_imgCisDomTyp.Create(12, 14, ILC_COLOR, 3, 0);


     gb_imgCisDomTyp.Add(&gb_bmpCisDom_0, (CBitmap*) NULL);
     gb_imgCisDomTyp.Add(&gb_bmpCisDom_P, (CBitmap*) NULL);
     gb_imgCisDomTyp.Add(&gb_bmpCisDom_E, (CBitmap*) NULL);
Roshan DavisCommented:
check the return value of "Add" function.

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Martin BodlákAuthor Commented:
You still don't understand me:
All images are loaded into image list, they are OK.
I can see them in ComboBoxEx when I drop down the list.
But as soon as I select any item in list, the list is closed and in edit line of combo there is no image with the selected item.
When I drop down the combo again, all images are OK with exception of the item which is currently selected (= in edit line of combo). This item has no image.
But when I select another item and again drop down the list, the image in the originally selected item is shown, but now the image from currently selected item is not shown.
Roshan DavisCommented:
This is just a guess..

Try to use CBEIF_OVERLAY with selected image and set its index.


Martin BodlákAuthor Commented:
I worked... Thanks and have a nice day!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now