怎样获取CComboBox中下拉列表中选定一项的内容?

gracezhu277 2005-04-19 03:32:54
我写了个基于对话框的程序,放了个CComboBox控件,用户在使用时,从ComboBox下拉表中选择一项,如何获取选定项的内容(注意是内容不是索引),并且以字符串类型传出,或者把对应的内容写入一个缓冲区。
...全文
898 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gracezhu277 2005-04-19
  • 打赏
  • 举报
回复
好了,现在可以了,真是谢谢各位了!但还是有问题,执行到fopen那句时,总说文件不存在!但我测试了下ch_filename这个字符串,里面确实拷贝了选定的名字。而且这个文件也确实存在,不知道什么原因。这个问题困扰我一天了,开始以为是获取选定项时不正确,但现在还是这样,晕了...
void CFomatManageDlg::OnSelchangeComboTem()
{
// 将用户选择的模板显示为界面
FILE *fp;
//MyComboBox myComboBox;
CComboBox *pMyComboBox=(CComboBox*)GetDlgItem(IDC_COMBO_TEM);
int i=pMyComboBox->GetCurSel();
CString ch_filename;
pMyComboBox->GetLBText(i,ch_filename);


if((fp=fopen(ch_filename,"r"))==NULL)
{
MessageBox("This file doesn't exist!","error",MB_OK);
}
}
anlywei 2005-04-19
  • 打赏
  • 举报
回复
m_Combo.InsertString(0,"please choose");
m_Combo.SetCurSel(0);
shenailin 2005-04-19
  • 打赏
  • 举报
回复
Gets a string from the list box of a combo box.

int GetLBText(
int nIndex,
LPTSTR lpszText
) const;
void GetLBText(
int nIndex,
CString& rString
) const;
Parameters
nIndex
Contains the zero-based index of the list-box string to be copied.
lpszText
Points to a buffer that is to receive the string. The buffer must have sufficient space for the string and a terminating null character.
rString
A reference to a CString.
idAnts 2005-04-19
  • 打赏
  • 举报
回复
m_Com.AddString(”please choose");
m_Com.SetCurSel(0);
gracezhu277 2005-04-19
  • 打赏
  • 举报
回复
还有,在对话框加载时,我想让comboBox的Edit框里显示一条提示语句如”please choose",但我用了SetWindowText和SetDlgItemText试过,都不行,怎么回事呢?
lu1172101275 2005-04-19
  • 打赏
  • 举报
回复
一楼讲得很明白
legendhui 2005-04-19
  • 打赏
  • 举报
回复
GetLBText
idAnts 2005-04-19
  • 打赏
  • 举报
回复
//
int i = m_Com.GetCurSel();
if(i!= -1)
{
CString rString;
m_Com.GetLBText(i,rString);
}

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧