Home | Overview | How Do I | Tutorial
A database form based on class CRecordView (for the MFC ODBC classes) or CDaoRecordView (for the MFC DAO classes) uses dialog data exchange (DDX) to exchange data between the form's controls and the field data members of the form's associated recordset object. This article explains how to use ClassWizard to set up the DDX connection between the controls and the recordset.
This connection is different from the normal use of DDX, which connects the controls in a dialog box directly to the data members of the associated dialog class. DDX for a record view object is indirect. The connection goes from form controls through the record view object to the field data members of the associated recordset object. For more information, see the articles Record Views and ClassWizard: Foreign Objects. The following table summarizes the mapping process.
Mapping Record View Controls to a Recordset
To | Do this |
Specify the form control | Select the record view class on ClassWizard's Member Variables tab and select one of the form's control IDs |
Specify the recordset data member to connect it to | Use the Add Variable dialog box to select a recordset data member indirectly |
The following procedure assumes you have already followed the procedures in the article ClassWizard: Creating a Database Form. Specifically, you've created a CRecordset-derived or CDaoRecordset-derived class and added some field data members to it, created a dialog-template resource, created a CRecordView-derived or CDaoRecordView-derived class, and associated the record view class with the recordset class. Your record view class is associated with the dialog-template resource, to which you've added controls with the Visual C++ dialog editor.
To map the form controls to the recordset
Important Use the drop-down list box to select a data member name from the associated recordset (a foreign object). The names that appear are of the form m_pSet->m_recordsetVarName
. You can type the name instead, but selecting from the drop-down list is faster and more accurate.
All variables of the recordset class appear in the box, not just variables of the currently selected data type.
By selecting a name from the drop-down list, you specify a connection that passes through the record view object to a field data member of its associated recordset object.
Tip If you're running ClassWizard with the Visual C++ dialog editor open, the following shortcut is available. Choose a control on the form; then press CTRL and double-click the mouse. This opens ClassWizard's Add Member Variables dialog box, where you can bind a recordset field data member to the control. (If you use this shortcut before a class has been created for the dialog template, ClassWizard opens and displays its Add Class dialog box.)
If you follow a simple rule when placing controls on your record view form, ClassWizard is able to pre-select the most likely recordset member in the dialog box. The rule is to place the static text label for the control ahead of the corresponding control in the tab order.
Tip You can use CTRL+double-click for pushbuttons too. In these cases, ClassWizard creates a message handler function for the BN_CLICKED notification message in your record view class. You can edit its code to specify the button's action.
See Also ClassWizard: Foreign Objects