BINDENRL: Databound Controls Version of the ENROLL Sample

Click to open or copy the BINDENRL project files.

The BINDENRL sample shows how to build a dialog application based on property pages, and how to bind data-aware controls with a data source control created outside the current property page. BINDENRL uses databound controls instead of using the MFC ODBC database classes (as the ENROLL sample does) and shows an alternative method for displaying records.

BINDENRL is a dialog-based application that uses a CPropertySheet class in the main frame window. Several databound controls and their corresponding data source controls are added to the dialog template in each property page. In addition, one data source control (Courses) is created in the main property sheet at run time. This data source is bound to the controls in different property pages (CourseID, Hours, and Title in the Courses page, and CourseID in the Sections page). The data binding is performed at run time in the OnInitDialog member function for each property page.

BINDENRL uses the ON_DSCNOTIFY macro to pass notifications between different data sources. For example, the Sections page shows only the sections of the current course and only students enrolled in the current section. To select the desired records, the dynamic SQL filters are set to the Sections and Students data source controls at run time by adding the WHILE clause to the SQL string defined in the Sections and Students data source controls. This code is executed in response to the Move event fired by the Courses and Sections data source controls.

Running the Sample

To run the sample, copy the files from the Visual C++ distribution CD. This copies the source files and the sample database Stdreg32.mdb. Next, define the data source name (DSN) "Student Registration" in the ODBC Administrator Control Panel application. Select the Microsoft Access driver, then select the sample database Stdreg32.mdb located on your hard drive.

After compiling the application, you can browse through the records on each property page by clicking the corresponding data source control.

This sample demonstrates the following keywords:

CWnd::Create; ON_ DSCNOTIFY; CWnd::BindDefaultProperty; CWnd::BindProperty