学习:Combo Box和List Box

/*
D:Visual_Studio_reposMFC3
*/
void CMy3Dlg::OnBnClickedButton1()
{
	CString  mString;

	//得到文本框的内容
	GetDlgItemText(IDC_EDIT_1,mString);

	//设置Combo组合框
	mCombo.AddString(mString);

	//默认选中Combo新增的内容
	mCombo.SetCurSel(mCombo.GetCount()-1);

	//默认选中Combo新增的内容
	mList.AddString(mString);
	mList.SetCurSel(mList.GetCount() - 1);
}


void CMy3Dlg::OnBnClickedButton2()
{
	CString mString;
	int nIndex;
	nIndex = mCombo.GetCurSel();
	
	//删除的逻辑操作
	mCombo.DeleteString(nIndex);
	if (nIndex < mCombo.GetCount()) {
		mCombo.SetCurSel(nIndex);
	}
	else {
		mCombo.SetCurSel(nIndex-1);
	}

	mList.DeleteString(nIndex);
	if (nIndex < mList.GetCount()) {
		mList.SetCurSel(nIndex);
	}
	else {
		mList.SetCurSel(nIndex - 1);
	}
}

//实时变化
void CMy3Dlg::OnCbnSelchangeCombo1()
{
	mList.SetCurSel(mCombo.GetCurSel());
}

原文地址:https://www.cnblogs.com/zpchcbd/p/12272891.html