BOOL CTestCombox::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
vector<VERSIONINFO>::iterator iter;
for (iter = m_vecVersionInfo.begin(); iter!= m_vecVersionInfo.end();iter++)
{
m_cmbBoxValue.AddString(iter->cstrName);
if (iter == m_vecVersionInfo.begin())
{
m_cmbBoxType.AddString(iter->Valtype.cstrType1);
m_cmbBoxType.AddString(iter->Valtype.cstrType2);
m_cmbBoxType.AddString(iter->Valtype.cstrType3);
m_cmbBoxType.SetCurSel(0);
}
}
m_cmbBoxValue.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
//添加 btnselectchanged 消息函数 关联2个combox
void CTestCombox::OnCbnSelchangeCombo1()
{
// TODO: 在此添加控件通知处理程序代码
//先将原来的所有type删掉
while (m_cmbBoxType.DeleteString(0))
{
;
}
//然后根据当前name添加相应的type
int iTotal = m_cmbBoxValue.GetCount(); //获取name的总数
int iIndex = m_cmbBoxValue.GetCurSel(); //获取当前name的序号
CString cstrValue;
m_cmbBoxValue.GetLBText(iIndex,cstrValue); //获取当前name
vector<VERSIONINFO>::iterator iterInfo;
for (iterInfo = m_vecVersionInfo.begin();iterInfo != m_vecVersionInfo.end();iterInfo++) //遍历整个容器,查找name值
{
if (iterInfo->cstrName == cstrValue) //查找到当前name的序号,将当前name的所有type添加到combox,并显示第一个
{
m_cmbBoxType.AddString(iterInfo->Valtype.cstrType1);
m_cmbBoxType.AddString(iterInfo->Valtype.cstrType2);
m_cmbBoxType.AddString(iterInfo->Valtype.cstrType3);
m_cmbBoxType.SetCurSel(0);
m_cmbBoxType.UpdateWindow();
}
}
}