组合框,列表框

来源:互联网 发布:战网客户端 for mac 编辑:程序博客网 时间:2024/04/30 17:06

组合框封装类:CComboBox

列表框封装类CListBox


首先将列表框和组合框都绑定控件变量,我们希望当按下添加按钮时,将数据从编辑框分别添加到列表框和组合框中去

添加按钮代码:

void Cdemo7Dlg::OnBnClickedButAdd(){// TODO: 在此添加控件通知处理程序代码CString strText;GetDlgItemText(IDC_EDT_TEXT,strText);m_cmb_demo.AddString(strText);//添加到组合框里m_cmb_demo.SetCurSel(m_cmb_demo.GetCount()-1);//当前选中新添加的成员m_lst_demo.AddString(strText);m_lst_demo.SetCurSel(m_lst_demo.GetCount()-1);}

删除按钮代码:
void Cdemo7Dlg::OnBnClickedButDelete(){// TODO: 在此添加控件通知处理程序代码int nIndex;  //索引nIndex=m_cmb_demo.GetCurSel();//当前选中的if(nIndex>-1)   //有选中的{m_cmb_demo.DeleteString(nIndex); //删除选中if(nIndex<m_cmb_demo.GetCount()) //如果nIndex索引还在范围内,则选中当前索引,否则选中第一个m_cmb_demo.SetCurSel(nIndex);elsem_cmb_demo.SetCurSel(0);}nIndex=m_lst_demo.GetCurSel();if(nIndex>-1){m_lst_demo.DeleteString(nIndex);if(nIndex<m_lst_demo.GetCount())m_lst_demo.SetCurSel(nIndex);elsem_lst_demo.SetCurSel(0);}}


0 0
原创粉丝点击