how to set image for each item in ComboboxEx?

D.D.K-2637 966 Reputation points
2021-05-31T21:01:46.397+00:00

Hi,
from this post,
I use the following code to assign an image to each item but it doesn't work ((no image is displayed)

CComboBoxEx mycombo;
CImageList m_ComboImageList;
m_ComboImageList.Create(24, 24, ILC_COLOR, 1, 1);
m_ComboImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1)); //only one. [image 24x24.ico]
fMfc_combobox_filllist(mycombo, listwchar_t); //fill list wchar_t for combobox
mycombo.SetImageList(&m_ComboImageList); //<-assign icon for all items

Am I missing something?

Thanks you!

Developer technologies | C++
{count} votes

2 answers

Sort by: Most helpful
  1. Igor Tandetnik 1,116 Reputation points
    2021-06-01T01:58:03.307+00:00

    SetImageList doesn't assign any icons to any items. It merely provides a list of icons that could be assigned to items. The actual assignment happens in SetItem or InsertItem, by setting COMBOBOXEXITEM::iImage and/or iSelectedImage members.

    1 person found this answer helpful.

  2. Guido Franzke 2,191 Reputation points
    2021-06-01T05:58:50.547+00:00

    Hello,
    have a look at this example: A-Combobox-with-bitmaps
    Regards, Guido

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.