MFC 中 CComboBox常用的使用方法
在工具栏中添加 CComboBox,属性:Type有三种格式【DropDown】【Simple】【Drop List】,
初始化下拉框数据:
1 2 3 4 5 6 7 8 9 10 11 | for ( int xh=0;xh<100;xh++){ //item="Item"+xh; char item[256]; sprintf(item, "Item%d" ,xh); int i= this ->IDC_DropDown.AddString(item); //添加数据 this ->IDC_DropDown.SetItemData(i,1000+xh); //添加附加的数据 这里的第一个参数,一定要是 AddString之后的返回结果,否则会获取不到附加值信息,已经测试过 this ->IDC_Simple.AddString(item); this ->IDC_DropList.AddString(item); } |
获取当前下拉框选中的索引:
1 | this ->IDC_DropDown.GetCurSel() |
获取选中的文本:
1 2 3 | String curText; this ->IDC_DropDown.GetLBText( this ->IDC_DropDown.GetCurSel(),curText); //获取选中的数据 AfxMessageBox(curText); |
删除选中的对象:
1 | this ->IDC_DropDown.DeleteString( this ->IDC_DropDown.GetCurSel()); //删除数据 |
获取附加的数据:
1 2 3 4 5 6 7 8 | int selectIndex = ( this ->IDC_DropDown.GetCurSel()); CString sdata; sdata.Format( "附件数据序号:%d" ,selectIndex); AfxMessageBox(sdata); DWORD_PTR text = this ->IDC_DropDown.GetItemData(selectIndex); CString sdata1; sdata1.Format( "附件数据:%d" ,text); AfxMessageBox(sdata1); |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)