Record View Code Created by AppWizard

HomeOverviewHow Do IFAQSampleTutorialODBC Driver List

ClassWizard (or AppWizard) overrides the view’s OnInitialUpdate and OnGetRecordset member functions. After the framework creates the frame window, document, and view, it calls OnInitialUpdate to initialize the view. OnInitialUpdate obtains a pointer to the recordset from the document. A call to the base class CView::OnInitialUpdate function opens the recordset. The following code shows this process for a CRecordView ? the code for a CDaoRecordView is similar:

void CSectionForm::OnInitialUpdate()
{
   m_pSet = &GetDocument()->m_sectionSet;
   CRecordView::OnInitialUpdate();
}

When the recordset opens, it selects records. CRecordset::Open or CDaoRecordset::Open makes the first record the current record, and DDX moves data from the recordset’s field data members to the corresponding form controls in the view. For more information about RFX, see the article Record Field Exchange (RFX). For more information about DFX, see the article DAO Record Field Exchange (DFX). For more information about DDX, see Dialog Data Exchange and Validation. For details of the document/view creation process, see Using the Classes to Write Applications for Windows.

Important   You should give your end users the capability to refresh the record view controls from the recordset. Without this capability, if a user changes a control’s value to an illegal value, he or she could be permanently stuck on the current record. To refresh the controls, you call the CWnd member function UpdateData with a parameter of FALSE. For an example, see Step 3 in the ENROLL tutorial — look at the OnRecordAdd member function in file SECTFORM.CPP. The tutorial begins in Creating a Database Application in Tutorials.