Assertion error when using CComboBox.AddString() method.
Posted on 2001-06-20
I have two Dialog frames and I am trying to populate a
CComboBox in the child dialog with elements from a CComboBox from the parent dialog. When I use the AddString
method when loading my child combobox I get an assertion
error at runtime in afwin2.nll at line 735 which seems to check if
the CComboBox is of the CWind class.
Here is the code I use in the parent to call the child:
// Create instance of child dialog
CAddEditDlg * AddProductDialog = new CAddEditDlg( this );
// This works ok so I know all attributes for
// child class have been created by now.
// Call method to load the child combobox passing the
// parent's filled combobox.
( m_main_combo_control );
int nButtonClicked = AddProductDialog->DoModal();
Here is the method in the child class:
( CComboBox & comboRef )
for( int i=0; i < comboRef.GetCount(); i++ )
comboRef.GetLBText( i, buffer );
// This prints with the correct content
// for buffer.
AfxMessageBox("Adding " + buffer );
// Here is where the assertion error appears.
// I have tried even hard coding a string
// literal like "hello" and I still get the error.
m_combo_control.AddString( (LPCTSTR) buffer );
m_combo_control.SetCurSel( 0 );
Any help would be greatly appreciated ...