This control enables the display and editing of data for a selected field with a special (internal) editor.
The following requirements must be met:
An (extended) example can be found in section 22.5.5.4.
How to create a new DataControl control:
Dim hDataControl As DataControl hDataControl = New DataControl ( Parent As Container ) As "event name"
Figure 22.5.5.1: Six DataControls in the selected area
The DataControl class has these properties:
Property | Data type | Description |
---|---|---|
Control | Control | Returns the specific editor for editing a specific field, as it depends on the field type which editor is used in the DataControl. Examples: Date: DateBox or Text: TextBox. |
Field | String | Specifies the field whose data is to be displayed and edited with the DataControl. The DB data comes from the first, higher-level data source (DataSource). You can also read out the value of the property. |
Modified | Boolean | The value is True if the content in the DataControl has been changed. The property can only be read. |
Valid | Boolean | Is True if the content of the DataControl is valid. |
Value | Variant | Sets the value for the DataControl. You can also read the property. |
Table 22.5.5.1.1 : Properties of the DataControl class
The DataControl class only has one relevant method: Update( ). The procedure reloads the (current) data content into the DataControl.
The DataControl class only has this special event:
Validate ( Value As Variant ): The event is triggered when the content of the DataControl needs to be validated. `Value` is the value of the DataControl list to be checked.
This event allows the user to add specific validation requests. To invalidate the data, simply stop the event with STOP EVENT.
Public Sub DataControl1_Validate(Value As Variant) If IsNull(Value) Then Return If Not IsInteger(Value) Then Return '-- Valid range: [0,100] If Value < 0 Or Value > 100 Then ' Diese Zeile wird vom Typ des Feldes und von den Werten bestimmt Stop Event Endif End
The example refers to a field in which date values - such as a birthday - are stored. In this case, the editor is a DateBox, but its Mode property is set to the value DateTime. Even if you have set the field type to Date, the empty time part is always automatically displayed after the correct date, as in `12/12/1978 00:00`. You can change the output format using the source text marked in red, which sets the Mode property of the DateBox to Date (= 0). The idea comes from Gianluigi (bagonergi@gmail.com).
Public Sub Form_Open() Dim hDateBox As Datebox '-- Configure DB connection (SQLite) hDBConnection.Type = "sqlite3" hDBConnection.Host = User.Home &/ "DatabasesSQLite" hDBConnection.Name = "Adressen" '-- Open DB connection hDBConnection.Open() '-- Define DB table DataSource1.Table = "adressliste" DataSource1.MoveFirst() '-- Connect the individual DataControls - prefix `dc` - with the corresponding database fields dcNachname.Field = "Nachname" dcVorname.Field = "Vorname" cdWohnort.Field = "Wohnort" dcPLZ.Field = "PLZ" dcStrasse.Field = "Strasse" dcEMailAdresse.Field = "EMailAdresse" dcWebAdresse.Field = "WebAdresse" dcHinweise.Field = "Hinweise" dcTelefonFestnetz.Field = "TelefonFestnetz" dcTelefonMobil.Field = "TelefonMobil" dcGebDatum.Field = "GebDatum" '-- Change the format of the (internal) date box of `dcGebDatum` via its mode property hDateBox = dcGebDatum.Children[0] hDateBox.Mode = 0 End
This displays the date correctly - without the time component:
Figure 22.5.5.4.1: Date display