如何将字符串添加到CComboBoxEx控件对象

如何将字符串添加到CComboBoxEx控件对象

本文介绍了如何将字符串添加到CComboBoxEx控件对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用类向导在组合框控件的对话框类中创建变量 - 键入CComboBoxEx。

I have used class wizard to create a variable in my dialog class for the combo box control - type CComboBoxEx.

我通过AddString向此成员变量添加一个字符串(...)

I am adding a string to this member variable via AddString(...)

但是我在这里得到一个断言失败:

However I am getting an assertion fail here:

_AFXCMN_INLINE int CComboBoxEx :: AddString(_In_z_ LPCTSTR lpszString)

     {UNUSED_ALWAYS(lpszString); ASSERT(FALSE);返回CB_ERR;}

_AFXCMN_INLINE int CComboBoxEx::AddString(_In_z_ LPCTSTR lpszString)
    { UNUSED_ALWAYS(lpszString); ASSERT(FALSE); return CB_ERR;}

为什么?

如果我将成员变量的类型更改为CComboBox,那么断言就会消失,但AddString(... )什么也没做,我的组合框仍然是空的。

If I change the type of the member variable to CComboBox then the assertion goes away but AddString(...) does nothing and my Combo box remains empty.

推荐答案


可以使用 InsertItem 添加项目。确保在已创建对话框和控件时调用它。例如,在
OnInitDialog 内。

The items can be added with InsertItem. Make sure that it is called when the dialog and control are already created. For example, inside ofOnInitDialog.


这篇关于如何将字符串添加到CComboBoxEx控件对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:23