How to add item to a combobox?

2019-09-20 10:50发布

I am a newbie to MFC. I don't know how to add values to a combobox. I have a vector class.

This is my code.

CellPhone cp;
vector<CellPhone> cellPhoneList;
cellPhoneList = cp.loadCellPhone();

m_pComboBox.SetCurSel(0);

for(unsigned int i=0; i<cellPhoneList.size(); i++)
{

  CString str = cellPhoneList[i].getSerialNumber();
  m_pComboBox.AddString(str);

}

serialNumber's type is CString.

combobox does not show serialNumber list.

how can I do?

标签: mfc combobox
2条回答
forever°为你锁心
2楼-- · 2019-09-20 11:19

The m_p ComboBox variable name suggests that this is a member pointer reference. Perhaps you meant to use:

m_pComboBox->SetCurSel(0);

and

m_pComboBox->AddString(str);

?

查看更多
Viruses.
3楼-- · 2019-09-20 11:19

Maybe you have to convert your .getSerialNumber() to a string in first place.

查看更多
登录 后发表回答