Share via


EXTBIND: Creating and Binding Databound Controls at Run Time

The EXTBIND sample shows how to bind data-aware controls across a dialog-box boundary. The data source can be initialized in one window, while the databound controls created in another window (for example, a modeless dialog box) can be bound to the data source at run time.

Run the sample to see information from the Employee table in the Pubs database. NorthWind DataSource is inactive in this dialog box until you press the NorthWind button to open the modeless dialog box. All controls in this dialog box are driven by NorthWind DataSource.

The main dialog template contains the control bound to the Pubs data source and several masked edit controls created at design time. The NorthWind dialog template contains only one Masked Edit control (see note below about Masked Edit controls). The rest of the controls (NorthWind DataSource, two DBGrids, Calendar) are created at run time.

All controls in the NorthWind dialog box are bound to the ODBC data source name (DSN) at run time, which is necessary because the data source control is in a separate dialog box. In addition, the NorthWind dialog box shows how to change the bound column of a simple control at run time. By clicking the Birth Date or Hire Date radio button, you change the calendar control binding (BirthDate or HireDate column, respectively). The same is possible for the Masked Edit control showing, in this case, First/Last name.

You must set up the following data source names (DSNs) to run the sample.

  • SQLServerPubs (the PUBS database that ships with SQL Server)

  • Northwind (the name of the Microsoft Access sample database, NORTHWIND.MDB)

Note   The Masked Edit control does not automatically format its contents.

When the Masked Edit Controls Format property is set, it does not automatically format its contents upon losing focus. When embedded in a Visual Basic or Access form, the control automatically formats its contents when the control loses focus.

The Masked Edit Control uses a proprietary Visual Basic interface called IVBFormat. Control container applications written with Visual C++ do not support this interface. The absence of IVBFormat support in a control container prevents the Masked Edit Control from automatically updating its contents as specified by the Format property.

The Masked Edit Control can still be used in a Visual C++ control container application. However, the automatic formatting feature will be disabled. Other properties, like the Mask property and databinding properties function properly in the absence of the IVBFormat support.

This sample demonstrates the following keywords:

CWnd::Create; CWnd::BindDefaultProperty; CWnd::GetDSCCursor