User Tools

Site Tools


Sidebar

Databases

k22:k22.5:k22.5.1:start

22.5.1 Class DataBrowser (gb.db.form)

The DataBrowser class presents a DB grid view that displays the content of a result object (Result data type). A navigation bar can be activated to navigate through the data records. You can use the 'Columns' property to specify which DB fields can be displayed and edited. The DB data is provided via the 'Datasource' control element.

22.5.1.1 Properties

The DataBrowser class has the following properties:

PropertyData typeDescription
CanCreate BooleanFor the value True, the DataBrowser has a CreateRecord button. You can also read the value of the property. A new data record can be created. The default setting is True.
CanDeleteBooleanThe DataBrowser has a Delete button for the value True. You can also read the value of the property. A selected data set can be deleted. The default setting is True.
ColumnsString[ ]Sets the fields that are displayed in the columns in the DataBrowser. You can also read the value of the property. If the property is not set, this restriction is missing and all fields are automatically displayed.
ControlBooleanIf the value is True, all icons of the control are displayed, such as New, Save, Delete, Refresh, MoveNext, MovePrevious, MoveFirst and MoveLast. You can also read out the value of the property. The default setting is True.
Data_GridView_DataUse this property to save the content of a cell during the Data event (Event Data ( Row As Integer, Column As Integer, Value As Variant )).
EditableBooleanIf the value is True, the contents of all cells in the TableView can be edited. You can also read the value of the property.
GridBooleanIf the value is True, a grid is displayed. You can also read out the value of the property.
HeaderBooleanIf the value is True, a header is displayed in the grid. You can also read out the value of the property.
LabelsString[ ]Replaces the field names in the header in the grid with the content of the string array in the specified order. You can also read out the value of the property.
OrientationIntegerSpecifies whether the icon list is displayed at the top, right, bottom or left in the DataBrowser. Use the constants Align.Top (19), Align.Bottom (35), Align.Right (2) or Align.Left (1) to specify the orientation. You can also read out the value of the property. The default setting is 1.
ViewTableViewReturns the table view used to display the DataBrowser contents.

Table 22.5.1.1.1 : Properties of the DataBrowser class

22.5.1.2 Methods

The class DataBrowser has only this special method DataBrowser.Update ( ). It reloads the (current) data content into the DataBrowser.

22.5.2 Events

The DataBrowser class has only one event Data ( Row As Integer, Column As Integer, Value As Variant ), which is relevant for the DataBrowser with regard to the database data:

  • Row is the row index.
  • Column is the column index.
  • Value is the value received from the database and displayed in the cell.

The event is triggered when the DataBrowser needs to display a specific cell. Use the Data property to define the content of a cell.

22.5.2.1 Examples

The 'contacts' table in the SQLite3 database 'contacts.sqlite' was created with this SQL statement and then filled with data:

hans@mint-183 ~ $ sqlite3 contacts.sqlite
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.
sqlite> CREATE TABLE IF NOT EXISTS contacts 
   ...> (
   ...> id INTEGER PRIMARY KEY  AUTOINCREMENT,
   ...> vorname TEXT,
   ...> nachname TEXT,
   ...> wohnort TEXT,
   ...> plz TEXT,
   ...> strasse TEXT,
   ...> email TEXT
   ...> );
sqlite> .databases
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /home/hans/contacts.sqlite                               
sqlite> .tables
contacts
sqlite> .quit
hans@mint-183 ~ $ 

The DataBrowser control element is responsible for displaying all data records that are not filtered out by a set data filter. This configuration results in the following screen:

Private Sub SetDBBrowserProperties()
 
  DataBrowser1.Columns = ["vorname", "nachname", "plz", "wohnort", "strasse", "email"]
  DataBrowser1.Labels = ["Vorname", "Nachname", "PLZ", "Wohnort", "Strasse", "EMail-Adresse"]
 
  DataBrowser1.Control = True    '-- Default: True
' DataBrowser1.CanCreate = True  '-- Default: True
  DataBrowser1.CanDelete = False '-- Default: True
  DataBrowser1.Editable = False
 
  DataBrowser1.View.Clear()
 
  DataBrowser1.View.Columns[0].Width = 90
  DataBrowser1.View.Columns[1].Width = 90
  DataBrowser1.View.Columns[2].Width = 60
  DataBrowser1.View.Columns[3].Width = 120
  DataBrowser1.View.Columns[4].Width = 125
 
  DataBrowser1.View.MoveTo(0, 0) '-- Required
 
End

BILD

Figure 22.5.2.1.1: Display 1

The configuration was changed as follows

Private Sub SetDBBrowserProperties()
 
  DataBrowser1.Columns = ["id", "vorname", "nachname", "plz", "wohnort", "strasse", "email"]
  DataBrowser1.Labels = ["ID", "Vorname", "Nachname", "PLZ", "Wohnort", "Strasse", "EMail-Adresse"]
 
  DataBrowser1.Control = True   '-- Default: True
' DataBrowser1.CanCreate = True '-- Default: True
' DataBrowser1.CanDelete = True '-- Default: True
  DataBrowser1.Editable = True
 
  DataBrowser1.View.Clear()
 
  DataBrowser1.View.Columns[0].Width = 30
  DataBrowser1.View.Columns[1].Width = 90
  DataBrowser1.View.Columns[2].Width = 90
  DataBrowser1.View.Columns[3].Width = 45
  DataBrowser1.View.Columns[4].Width = 120
  DataBrowser1.View.Columns[5].Width = 125
  DataBrowser1.View.Columns[6].Width = 1
 
  DataBrowser1.View.MoveTo(0, 0) '-- Required
 
End

Comment

  • All fields are now displayed in the DataBrowser with the changed configuration.
  • All icons in the navigation bar are visible.
  • The individual field contents can be changed in the table itself (edit mode).
  • The data record with the field value id = 7 is currently changed.
  • A field width is specified for the last field - here with the value 1. This means that the last field is only as wide as the remaining space allows. A horizontal scroll bar is omitted.

Note

The fields can be sorted by clicking on the (display) field name. The following applies: First click: descending sorting (▼), second click: ascending sorting (▲) and third click: no sorting - no symbol is displayed.

Picture2

Figure 22.5.2.1.2: Display 2

The 'DataSource' control provides the controls in the container with all the data of the selected database to which the connection was made. You can select which database data is actually available for display using the Table and Filter properties:

    DataSource1.Connection = DBCS.DBConnection
    DataSource1.Table = "contacts"

'-- Filtering is switched off
'-- DataSource1.Filter = “id > 4 AND city <> ‘Berlin’ AND city NOT LIKE ‘G%’”

Without an additional filter, this display 3 results together with the second configuration:

Picture3

Figure 22.5.2.1.3: Display 3

To determine the selected line in the DataBrowser:

selectedRow = DataBrowser.View.Row
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.1/start.txt · Last modified: 07.05.2024 (external edit)

Page Tools