Visual Basic Concepts
To create interfaces for data entry, data editing, or data viewing, Visual Basic forms and controls have always offered versatility and ease of programming.
In version 6.0, several new data-aware (data-bound) controls have been added. In addition to these new controls, the new Validate event and CausesValidation property prevent a control from losing focus until all data has been validated. For example, you can create data-entry forms that validate data by preventing the user from tabbing off the form until all fields have been filled in.
Another enhancement always available to you is the Microsoft Data Formatting Object Library. This new object library allow you to format data and preserve the underlying format to write back to the database.
New Data-Aware Controls
Several new ActiveX controls, specifically designed to view and/or edit data, have been added. These include:
- DataGrid Control — a new grid control that can work with the ADO Data Control or ADO Recordset objects.
- DataList Control — a control that functions exactly like the DBList control, but is optimized for use with OLE DB data sources.
- DataCombo Control — functions like the DBCombo control, but can use OLE DB data sources.
- Hierarchical FlexGrid Control — capable of displaying hierarchical cursors created with the Data Environment.
- DataRepeater Control — lets you use a user control to display data, and "repeats" the control to view multiple records.
- MonthView Control — displays dates graphically as a calendar.
- DateTimePicker Control — similarly to the MonthView control, it displays dates in a text box; clicking the text box causes a graphic calendar to drop down for selection of a new date.
Data Binding Capabilities Added to Existing Controls
Intrinsic controls and many ActiveX Controls have new data properties associated with them now, in addition to the DataSource and DataField properties that have always existed. These are the four properties of interest:
- : Returns or sets the source of data for a control. You can now dynamically set the DataSource of a control or object at runtime to any valid data source, for example: an ADO Recordset, the DataEnvironment, a class that’s a data source, or to a data source control on the form.
- : Returns or sets the specific data set within the source to use. Data sources in Visual Basic 6.0 can contain multiple sets of data, and the DataMember property lets you specify which set of data to use. (Not all data sources have multiple members, for example the ADO Data Control returns only a single recordset.) The Data Environment, on the other hand, returns a DataMember for each Command defined. Visual Basic displays a list of available data members when this property is selected.
- : Returns or sets the specific field to bind a control to. (Same functionality as in previous versions of Visual Basic.)
- : Lets you define the automatic formatting of data as its retrieved from the data source.
The first three properties narrow in scope, from the DataSource down to the DataField, qualifying the source of the data. However, for complex data consumers such as the DataGrid, the DataField and DataFormat properties aren’t required, as the control handles them for you. For more information about the difference between simple-bound and complex-bound controls, see Creating Data-Aware Classes.
The controls which can be data bound using some or all of these properties include:
- CheckBox Control
- ComboBox Control
- DataCombo Control (new)
- DataGrid Control (new)
- DataList Control (new)
- DataRepeater Control (new)
- DateTimePicker Control (new)
- DBCombo Control
- DBList Control
- FlexGrid Control
- Hierarchical FlexGrid Control (new)
- Image Control
- ImageCombo Control (new)
- Label Control
- ListBox Control
- Masked Edit Control
- MonthView Control (new)
- MSChart Control
- PictureBox Control
- RichTextBox Control
- TextBox Control
Additionally, the new Extender object also includes the DataSource, DataMember, and DataField properties. The Extender object is used to program controls added dynamically to your forms. For more information on the Extender and adding controls at run time, see and .
Data validation is now easier using the Validate event with the CausesValidation property. Using the two new features in tandem, you can prevent a control from losing focus until the information it contains has been validated. For more information about these features, see Validating Control Data by Restricting Focus.