Sandeep Kumar
Sandeep Kumar

Reputation: 105

Adding strings to a combobox which is a member of CComboBoxEx

I want to add an associated Icon along with each string to a combo box. I am using CComboBox class of MFC and as CComboBox dosent give me any option to set image list

I tried to use CComboBoxEx which is an extended class of CComboBox I created a control variable m_cMyCombo and tried to add strings and also set the image list.

I am doing m_cMyCombo.AddString(_T("test")) but it asserts. I am trying to add this in my OnInitDialog() and i am sure the control is been created already as it dosent giev me any problem in DoDataExchange()

What could be the issue ?

Upvotes: 0

Views: 1126

Answers (1)

Andy
Andy

Reputation: 30418

You shouldn't call AddString() to add items to a CComboBoxEx. Instead, you should call InsertItem():

COMBOBOXEXITEM item = { 0 };
item.mask = CBEIF_TEXT;
item.iItem = 0;
item.pszText = L"Item 1";
m_comboEx.InsertItem(&item);

The COMBOBOXEXITEM structure will also let you set which image in the image list to use for this item.

Upvotes: 1

Related Questions