Share via


Disabling Combo Box Logic in Add Mode in DaoEnrol

Step 2 implemented a handler for selecting a course in the combo box. The handler requeried the parameterized CSectionSet for the newly selected course. In Step 3, the combo box takes on the additional duty of allowing the user to specify the course for a new section record being added. During add mode, you don’t want to requery the recordset when the user selects a course from the combo box. Therefore, you need to put the requery logic inside an if clause that is executed only if add mode isn’t in effect.

Suggested Reading in the Visual C++ User’s Guide

To disable normal combo box logic while in add mode

  1. Use ClassView to jump to the OnSelendokCourseList handler in class CSectionForm.

  2. Place an if block around the requery code in the OnSelendokCourseList handler, so the handler now appears as follows:

    void CSectionForm::OnSelendokCourselist()
    {
    if (!m_pSet->IsOpen() )
    return;    m_ctlCourseList.GetLBText(m_ctlCourseList.GetCurSel(),
    m_pSet->m_strCourseIDParam);
    if (!m_bAddMode)
    { 
    m_pSet->Requery();
    if (m_pSet->IsEOF())
    {
    m_pSet->SetFieldNull(&(m_pSet->m_CourseID), FALSE);
    m_pSet->m_CourseID = m_pSet->m_strCourseIDParam;
    }
    UpdateData(FALSE);
    }
    }