Binding the Combo Box Control to a Recordset Field and a CComboBox Variable

Now that you have replaced the edit control for the m_CourseID member of CSectionSet with a combo box, you need to:

You will later use member functions of CComboBox, such as AddString, to fill and read the combo box.

When you complete the next three procedures, the combo box control will have two member variables associated with it: (1) the foreign member variable, m_CourseID, in the recordset associated with the record view, and (2) the CComboBox member variable in the record view class.

ClassWizard supports having two such member variables bound to the same control.

To remove the old edit control binding

  1. From the View menu, click ClassWizard.

  2. Click the Member Variables tab.

  3. In the Class name box, select class CSectionForm (if it isn’t already selected).

  4. In the Control IDs box, select IDC_COURSE and click Delete Variable.

  5. Click OK.

To bind the combo box control to the recordset member

  1. In the dialog editor, press CTRL and double-click the combo box control to open the Add Member Variable dialog box.

    Recall that when you changed the edit control to a combo box, you also changed the tab order so the combo box would directly follow the Course static text control. ClassWizard chooses the member variable name based on the recordset member associated with the static text control that directly precedes it in tab order.

  2. Click OK to accept m_pSet->m_CourseID as the member variable name and exit the Add Member Variable dialog box.

To bind the combo box control to the view’s CComboBox member variable

  1. Open ClassWizard and, if necessary, click the Member Variables tab.

  2. In the Control IDs list, highlight IDC_COURSELIST, and click Add Variable.

    The Add Member Variable dialog box appears.

  3. In the Member variable name box, type m_ctlCourseList.

  4. In the Category box, select Control.

    Note that this automatically selects CComboBox as the Variable type.

  5. Click OK to exit the Add Member Variable dialog box.

  6. Click OK to exit ClassWizard.

  7. Close the dialog editor and property page and save your work.