Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another CComboBox empty issue

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
I'm using AddString() method of the CComboBox class in MFC, and I'm tracing every important step in the procedure, and the AddString() method always returns 0 and never adds anything to the combobox. Here is the code of the function:

Code:
void CFuel_Refund_MFCView::LoadTractors(void)
{
	m_Tractor.ResetContent();
	ASSERT( m_Tractor.GetCount() == 0 );

	CRecordset cRec( theApp.GetDatabase() );

	if (theApp.GetDatabase()->GetTractors( cRec ))
	{
		if( !(cRec.IsBOF() && cRec.IsEOF())) {
			TRACE("Adding tractors now\n");
			cRec.MoveFirst();
			CString tractor;
			int item;

			while (!cRec.IsEOF())
			{
				cRec.GetFieldValue( _T("UNIT"), tractor );
				TRACE1("Adding tractor %s\n", tractor);
				item = m_Tractor.AddString( tractor );
				if( item == CB_ERR || item == CB_ERRSPACE ) {
					TRACE("Error inserting tractor\n");
				} else {
					TRACE1("Item inserted at item %d\n", item);
				}
				cRec.MoveNext();
			}
		}
	}
}

As you can see, the function is pretty straight forward, and I'm seeing all the records from the database that should be inserted, but never are.

Any suggestions as to what might be happening?

I thought at first it might be because the window isn't created, but if that was the case, then I should get an ASSERTION I would think. And 0 should be a valid return value. At this point I'm completely at a loss.

I have the DDX_Control set up as well, so the variable is correct.
 
Nevermind, in my infinite wisdom I selected the extended combobox when building the dialog window which doesn't support AddString().

It works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top