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.
The DataBrowser class has the following properties:
Property | Data type | Description |
---|---|---|
CanCreate | Boolean | For 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. |
CanDelete | Boolean | The 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. |
Columns | String[ ] | 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. |
Control | Boolean | If 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_Data | Use this property to save the content of a cell during the Data event (Event Data ( Row As Integer, Column As Integer, Value As Variant )). |
Editable | Boolean | If the value is True, the contents of all cells in the TableView can be edited. You can also read the value of the property. |
Grid | Boolean | If the value is True, a grid is displayed. You can also read out the value of the property. |
Header | Boolean | If the value is True, a header is displayed in the grid. You can also read out the value of the property. |
Labels | String[ ] | 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. |
Orientation | Integer | Specifies 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. |
View | TableView | Returns the table view used to display the DataBrowser contents. |
Table 22.5.1.1.1 : Properties of the DataBrowser class
The class DataBrowser has only this special method DataBrowser.Update ( ). It reloads the (current) data content into the DataBrowser.
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:
The event is triggered when the DataBrowser needs to display a specific cell. Use the Data property to define the content of a cell.
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
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
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.
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:
Figure 22.5.2.1.3: Display 3
To determine the selected line in the DataBrowser:
selectedRow = DataBrowser.View.Row