A good place to fill the combo box with a list of course names is in CSectionForm
’s override of CRecordView’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.
To fill the combo box
OnInitialUpdate
. m_pSet = &GetDocument()->m_sectionSet;
— add the code below (don’t replace any code):// Fill the combo box with all of the courses
CEnrollDoc* pDoc = GetDocument();
pDoc->m_courseSet.m_strSort = "CourseID";
if (!pDoc->m_courseSet.Open())
return;
// Filter, parameterize and sort the CSectionSet recordset
m_pSet->m_strFilter = "CourseID = ?";
m_pSet->m_strCourseIDParam = pDoc->m_courseSet.m_CourseID;
m_pSet->m_strSort = "SectionNo";
m_pSet->m_pDatabase = pDoc->m_courseSet.m_pDatabase;
You will add the necessary member declaration in Setting Up the Parameter later in this lesson.
CRecordView::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);
The code you have added above is explained in the topics Setting Up the Filter and Setting Up the Parameter, later in this lesson.