combobox添加下拉项的问题

xidiancjw 2010-07-23 01:03:39
在ComboBox控件的dropdown()函数中写了如下代码:
CString strTemp;
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->ResetContent();
for(int i=1;i<=100;i++)
{
strTemp.Format("%d",i);
if(itoa(strTemp)>100)
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->AddString(strTemp);
}
执行上述代码后,要对ComboBox控件中一行也没有添加的情况进行提示。如何对没有添加任何信息这种情况进行判断?
请教大虾们
...全文
243 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xidiancjw 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 visualeleven 的回复:]
类似这样

C/C++ code

BOOL CXXDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(WM_COMMAND == pMsg->message)
{
if(CB……
[/Quote]
加了这个函数好像没有效果啊。。。
xidiancjw 2010-07-24
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 hongya6088 的回复:]
判断一下如果没有添加,就转移一下焦点
比如还有一个Edit控件,((CEdit*)GetDlgItem(ID_EDIT))->SetFoucse();
[/Quote]
不行啊,焦点转移了,照样有下拉发生
hongya6088 2010-07-23
  • 打赏
  • 举报
回复
strTemp.Format("%d",i);
if(itoa(strTemp)>100)

为什么转来转去的??转的还有问题
直接:
strTemp.Format("%d",i);
if(i>100)

判断一下如果没有添加,就转移一下焦点
比如还有一个Edit控件,((CEdit*)GetDlgItem(ID_EDIT))->SetFoucse();
Eleven 2010-07-23
  • 打赏
  • 举报
回复
类似这样

BOOL CXXDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(WM_COMMAND == pMsg->message)
{
if(CBN_DROPDOWN == HIWORD(pMsg->wParam) && IDC_COMBO1 == LOWORD(pMsg->wParam))
{
AfxMessageBox(_T("DOWN"));
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Eleven 2010-07-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 xidiancjw 的回复:]
dropdown()函数中的代码
{
CString strTemp;
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->ResetContent();
for(int i=1;i<=100;i++)
{
strTemp.Format("%d",i);
if(itoa(strTemp)>100)
((CComboBox*……
[/Quote]
------------------
你不显示下拉框,可以在PreTranslateMessage中过滤CBN_DROPDOWN
linsj585 2010-07-23
  • 打赏
  • 举报
回复
atoi
GetCount();
Eleven 2010-07-23
  • 打赏
  • 举报
回复
if(itoa(strTemp)>100)
-------------------------
这写的什么?能通得过编译??
xidiancjw 2010-07-23
  • 打赏
  • 举报
回复
dropdown()函数中的代码
{
CString strTemp;
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->ResetContent();
for(int i=1;i<=100;i++)
{
strTemp.Format("%d",i);
if(itoa(strTemp)>100)
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->AddString(strTemp);
}
if(m_box.getcount()==0) //m_box是关联ComboBox的控件类型变量
{
AfxMessageBox("空!");
}
}
怎么弹出对话框框后,界面上的控件还是会显示下拉。怎样处理能让它出提示后,不再出现下拉?
blpluto 2010-07-23
  • 打赏
  • 举报
回复
GetCount()像这样~~~MSDN上的例子

// Add 10 items to the combo box.
CString strItem;
for (int i = 0; i < 10; i++)
{
strItem.Format(_T("item %d"), i);
m_pComboBox->AddString(strItem);
}

// Verify the 10 items were added to the combo box.
ASSERT(m_pComboBox->GetCount() == 10);



梧桐126 2010-07-23
  • 打赏
  • 举报
回复
((CComboBox*)GetDlgItem(IDC_COMBO_CF))->GetSel()==-1
那个函数拼写好象错了,就是取得当前选择的项,-1表示没选的情况
webipstin 2010-07-23
  • 打赏
  • 举报
回复
CComboBox::GetCount
int GetCount( ) const;

Return Value

The number of items. The returned count is one greater than the index value of the last item (the index is zero-based). It is CB_ERR if an error occurs.

Remarks

Call this member function to retrieve the number of items in the list-box portion of a combo box.

Example

// The pointer to my combo box.
extern CComboBox* pmyComboBox;

// Add 10 items to the combo box.
CString str;
for (int i=0;i < 10;i++)
{
str.Format(_T("item %d"), i);
pmyComboBox->AddString( str );
}

// Verify the 10 items were added to the combo box.
ASSERT(pmyComboBox->GetCount() == 10);


blingpro 2010-07-23
  • 打赏
  • 举报
回复
getitemcount之类的函数吧,具体名称不清楚,查一下msdn
gl

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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