A good place to fill the combo box with a list of course names is the CSectionForm
override of CDaoRecordView’s OnInitialUpdate member function. As part of its own initialization, the form fills the combo box. The overall logic is as follows:
CCourseSet
recordset based on the Course table.CCourseSet
, add the CourseID to the combo box.
The code in the following procedure fills the combo box and also filters, parameterizes, and sorts the CSectionSet
recordset. Filtering, parameterization, and sorting are explained in topics that follow.
OnInitialUpdate
to jump to its definition in SectForm.cpp.m_pSet = &GetDocument()->m_sectionSet;
add the code below (don’t replace any code):
// Fill the combo box with all of the courses
CDaoEnrolDoc* pDoc = GetDocument();
pDoc->m_courseSet.m_strSort = "CourseID";
try
{
pDoc->m_courseSet.Open();
}
catch(CDaoException* e)
{
AfxMessageBox(e->
m_pErrorInfo->m_strDescription);
e->Delete();
return;
}
// Filter, parameterize and sort the
// CSectionSet recordset
m_pSet->m_strFilter =
"CourseID = CourseIDParam";
m_pSet->m_strCourseIDParam =
pDoc->m_courseSet.m_CourseID;
m_pSet->m_strSort = "SectionNo";
m_pSet->m_pDatabase =
pDoc->m_courseSet.m_pDatabase;
Catch any exceptions so that errors are reported to the user. Unlike ODBC, DAO errors come directly from the underlying DAO object. Additional information about DAO errors can be found in the DAO SDK.
You’ll add the necessary member declaration in the topic Parameterizing the Filter in DaoEnrol.
CDaoRecordView::OnInitialUpdate();
add the following code:
m_ctlCourseList.ResetContent();
if (pDoc->m_courseSet.IsOpen())
{
while(!pDoc->m_courseSet.IsEOF())
{
m_ctlCourseList.AddString(
pDoc->m_courseSet.m_CourseID);
pDoc->m_courseSet.MoveNext();
}
}
m_ctlCourseList.SetCurSel(0);