Share via


Binding DaoEnrol’s Controls to Recordset Fields

With the form designed, it’s time to indicate which edit controls map to which table columns — or, more precisely, which controls map to which recordset field data members. To perform this task, you use ClassWizard’s “foreign object” mechanism.

Suggested Reading

  • , Visual C++ Programmer’s Guide

  • , Visual C++ User’s Guide

Normally, you use ClassWizard to bind controls in a dialog box or form to member variables of your CDialog- or CFormView-derived class. In the case of CDaoRecordView, though, you bind the form’s controls not to data members of the record view class but to data members of the recordset class associated with the record view.

Your CDaoRecordView-derived class — CSectionForm in this case — has a data member called m_pSet. You can view m_pSet in the ClassView of CSectionForm. This data member is a pointer to CSectionSet, DaoEnrol’s recordset class. Recall that you viewed this recordset class in the Member Variables tab of ClassWizard (see the figure Table Columns Mapped to Recordset Data Members).

The control bindings go through m_pSet to the corresponding field data members of CSectionSet. For example, in the following procedure, you will bind the Course edit control to:

m_pSet->m_CourseID

To bind a form control to a recordset data member

  1. If necessary, from ResourceView, expand the Dialog folder and double-click IDD_DAOENROL_FORM to open the dialog box inside the dialog editor.

  2. In the dialog editor window, hold down the CTRL key and double-click the Course edit control.

    ClassWizard’s Add Member Variable dialog box appears, with a proposed field name selected for you in the Member variable name box. ClassWizard chooses this name based on the caption of a static text control that falls previous to the edit control in the tab order. For example, for IDC_COURSE, the control’s caption is “Course,” and the Member variable name box should display:

    m_pSet->m_CourseID
    
  3. Click OK in the Add Member Variable dialog box to accept the name.

  4. Repeat steps 2 and 3 for each of the other edit controls on the form.

    It isn’t necessary to create mappings for the static text controls.

  5. Save your work.

Note   Using CTRL+double-click in the dialog editor is a ClassWizard shortcut for mapping form controls to members of the associated dialog box, form view, or record view class. Use it on a button to create a command handler function for the button. Use it on other controls to create a class member variable.

You can view the complete mappings for class CSectionForm in the ClassWizard Member Variables tab. For example, where IDC_COURSE appears in the Control IDs column, you’ll see ->m_CourseID in the corresponding Member column.