The Refresh command cancels add mode, if the user had previously chosen Add, or it discards any changes the user may have made on the form for the current record. In the first case, Enroll cancels the add mode by calling:
CRecordset::Move(0);
When you call AddNew to begin the add operation, the framework stores a copy of the current record’s fields before allowing the user to enter new values in the record view’s controls. Calling Move as shown here “refreshes” the current record — and effectively cancels the add operation. It restores the record that was current before add mode began. This also works if you called Edit instead of AddNew.
When the user cancels add mode, Enroll makes the Section control read-only again, for reasons explained earlier.
To implement the Refresh command
OnRecordRefresh
starter handler in class CSectionForm
.if (m_bAddMode)
{
m_pSet->Move(0);
m_ctlSection.SetReadOnly(TRUE);
m_bAddMode = FALSE;
}
// Copy fields from recordset to form, thus
// overwriting any changes the user may have made
// on the form
UpdateData(FALSE);
Note The source files for Enroll Step 3 on your distribution CD-ROM include functional toolbar buttons connected to the Add, Refresh, and Delete commands on the Record menu. The installed Step 3 source code supplies these toolbar buttons for Enroll. If you want to create toolbar buttons and link them to the Enroll command, examine the buttons and code provided in the Step 3 source code. For more information on creating toolbar buttons, see Edit Scribble’s Toolbar in Scribble, Lesson 5.