Customizing the Dialog Template for the Section Form

Along with the classes, AppWizard creates a dialog template resource named IDD_ENROLL_FORM, which the CRecordView-derived class, CSectionForm, uses to display its form controls. Because CRecordView is derived from CFormView, a record view’s client area is laid out by a dialog template resource. The layout of the form is up to you. AppWizard places one static text control on the dialog template resource, labeled “TODO: Place form controls on this dialog.”

Suggested Reading

In the following procedure, you will replace this text with controls that correspond to columns in the table (via the field data members of the recordset). The table below lists the columns and their associated edit control IDs and variable names.

Enroll's Controls and Member Variables

Column name Control ID Variable Name
Course IDC_COURSE
m_pSet->m_CourseID
Section IDC_SECTION
m_pSet->m_SectionNo
Instructor IDC_INSTRUCTOR
m_pSet->m_InstructorID
Room IDC_ROOM
m_pSet->m_RoomNo
Schedule IDC_SCHEDULE
m_pSet->m_Schedule
Capacity IDC_CAPACITY
m_pSet->m_Capacity

To customize Enroll’s form

  1. In ResourceView, expand the Enroll resources folder.

  2. Expand the Dialog folder.

  3. Double-click IDD_ENROLL_FORM.

    The dialog editor opens and displays the dialog box with the corresponding ID.

  4. Select and delete the static control that says TODO: Place form controls on this dialog.

  5. Design Enroll’s Section form to resemble the figure below, using static controls and edit controls.

    Tip   You can press CTRL before you click a dialog box control; then release the CTRL key and click in the dialog box multiple times to add multiple copies of the control. For instance, if you want six edit controls, click six times. Click the selection arrow to stop adding controls.

    Resize the dialog box as needed. You can either add the controls in pairs (that is, first a static text control and then the corresponding edit control, and so on) or later change the Tab order of the controls, as described at the end of this topic, so that they are paired in this way. This becomes important when you bind the controls to recordset fields, described in the next topic.

  6. Choose Properties from the View menu to display the Properties window, and then pin it down so that it stays open while you add and edit the dialog box controls.

  7. For each edit control, use the ID box in the Properties window to specify an ID based on the table column names (for example, IDC_COURSE). This is only a convention, but it is used throughout the tutorial.

    Note   The “Edit” caption that appears in each edit control is not visible to the user at run time, so you needn’t worry about deleting it. To view the dialog as it will appear at run time, press CTRL+T to enter test mode for the dialog box. Press ESC to cancel test mode.

    The Layout of Enroll’s Section Form

  8. Make the Course and Section edit controls read-only. To do so, select the Styles tab in the Properties window and set the Read-only check box. (The other edit controls are updatable.)

    According to a common rule in the user-interface design of database forms, the user shouldn’t be able to update these key fields. If users want to change a course number or section of a Section record, they must delete the old Section record and add a new one to avoid possibly violating the referential integrity of the database. Enroll tutorial Step 3 implements Add and Delete functionality.

  9. Save your work.

    It’s a good idea to periodically back up your work.

If you did not add the static text and corresponding edit controls in order, one after the other, you need to change the tab order. In either case, you can easily check the current tab order and change it if necessary.

To view or change the tab order of controls

  1. With the dialog resource open, from the Layout menu click Tab Order.

    You’ll see numbers depicting the current tab order of the controls.

  2. Specify the tab order you want by clicking each control in that order.

    As you click, you’ll see the numbering change to reflect your choice.

    For Enroll, specify a tab order such that each edit control is preceded in the tab order by the static text control that describes it. By specifying this tab order, you enable ClassWizard to derive a name for the edit control when you bind it to a data member, as you’ll do in the next section.

  3. Press ESC to exit Tab Order mode.

    Leave the dialog editor open for the next procedure.