User Tools

Site Tools


Sidebar

Databases

k22:k22.5:k22.5.5:start

22.5.5 Class DataControl (gb.db.form)

This control enables the display and editing of data for a selected field with a special (internal) editor.

The following requirements must be met:

  • There is a connection from the DB client to the selected database.
  • The DataControl is located in the DataSource container.
  • The DB table to be accessed is defined in the DataSource.
  • The field whose data is to be displayed and edited is specified for the DataControl.

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" 

B1

Figure 22.5.5.1: Six DataControls in the selected area

22.5.5.1 Properties

The DataControl class has these properties:

PropertyData typeDescription
ControlControlReturns 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.
FieldStringSpecifies 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.
ModifiedBooleanThe value is True if the content in the DataControl has been changed. The property can only be read.
ValidBooleanIs True if the content of the DataControl is valid.
ValueVariantSets the value for the DataControl. You can also read the property.

Table 22.5.5.1.1 : Properties of the DataControl class

22.5.5.2 Methods

The DataControl class only has one relevant method: Update( ). The procedure reloads the (current) data content into the DataControl.

22.5.5.3 Events

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

22.5.5.4 Example

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:

B2

Figure 22.5.5.4.1: Date display

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k22/k22.5/k22.5.5/start.txt · Last modified: 07.05.2024 (external edit)

Page Tools