Add strings to MFC ComboBox

2019-09-19 17:05发布

问题:

Trying to add strings to ComboBox:

BOOL CMyAppDlg::OnInitDialog()
{

    CComboBox *combo= (CComboBox *)GetDlgItem(IDC_COMBO_TT);
    combo->AddString("s1");
    combo->AddString("s2");

    // ...
    return TRUE;
}

Why ComboBox list is still empty?

回答1:

Do you see the first string if you call combo->SetCurSel(0)? If so it means the combo box drop down size is zero. In the visual dialog editor click on the combo's down arrow then drag the bottom edge down to resize the drop down part.