怎样才能在子对话框里用函数给combolist添加字符串?
为什么我用函数初始化combolist,已经通过debug,但是在执行的时候总是出错呢?

解决方案 »

  1.   

    不知道你的代码是怎么样的,所以不好回答,得到combolist的指针(GetDlgItem),然后就可以插入字符串了
      

  2.   


    CAddDialog::CAddDialog(CWnd* pParent /*=NULL*/)     
    : CDialog(CAddDialog::IDD, pParent)
    { CString str[3]={"在役","已退役","未服役"};
    int i;
    int index;
    for (i=0;i<3;i++)
    {
    index=m_army.AddString(str[i]);
    m_army.SetItemData(index,i);
    }
    m_army.SetCurSel(1);
    //{{AFX_DATA_INIT(CAddDialog)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    CDatabase m_database;
    if(!m_database.IsOpen())
    if(!m_database.Open(_T("db")))
    MessageBox("连接数据库出错");
    }错误信息:Debug Assertion Failed!For information on how your program can cause an assertion failure,see
    the Visual C++documentation on asserts. 
    大侠们请指点,谢谢!
      

  3.   

    你不能在类的构造函数里对控件初始化,因为这时控件窗口还没有建立,要在WM_INITIDIALOG
    消息中初始化