默认项目显示在不可编辑的组合框中

Default item showing in non-editable comboBox

本文关键字:组合 编辑 项目 显示 默认      更新时间:2023-10-16

我的GUI C++应用程序(Visual Studio 2012)中有一个不可编辑的组合框,我想从集合中选择该框中的默认项/值(所有项/值)。希望有人能帮助我实现这一点?

假设您已经填充了禁用的组合框,如下所示:

LPCTSTR s[] = {_T("Blue"), _T("Red"), _T("Yellow")};
CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_COLOR);
if(pCombo)
{
    for(int i=0; i<3; ++i)
    {
        pCombo->AddString(s[i]);
    }
    pCombo->SetCurSel(1); // <- sets the default value. here it would be "Red"
}

如代码片段所示,您只需设置当前所选项目(基于索引)