[Gambas-user] Using DataBrowser for a table which

John Rose john.aaron.rose at ...626...
Wed Aug 22 16:24:41 CEST 2012


1) You must embed the DataSource on "centre" inside a DataSource on 
"country" which points at the current country.

2) The name of the country primary key must be the same in all tables, 
so that Gambas automatically detects them.

Thanks, Benoit. I understand a little better. 
Now I have:
the Primary Key for the country table as country_id, 
country_id for the Foreign Key (to the country table) in the centre table. 
DataBrowserCentre embedded in DataSourceCentre
                              which is embedded in DataSourceCountry, 
DataSourceCountry.Filter as "country_id = " & CountryId,
DataSourceCentre.Filter as "country_id = " & CountryId),
(where CountryId is a variable containing the appropriate value).

I've started with a new database (i.e. all tables are empty of data). The relevant code for the button to start Centre Maintenance is:

Public Sub ButtonCentreMaintenance_Click()
  Dim hForm As FCentreMaintenance
  Print "CountryId=", CountryId
  hform = New FCentreMaintenance
  hForm.TextBoxCountry.Text = Country
  hForm.TextBoxCountryId.Text = CountryId
  hForm.DataSourceCountry.Connection = MDatabase.DatabaseConnection
  hForm.DataSourceCountry.Table = "country"
  hForm.DataSourceCountry.Filter = "country_id = " & CountryId
  Print "hForm.DataSourceCountry.Filter = ", hForm.DataSourceCountry.Filter
  hForm.DataSourceCountry.Update()
  hForm.DataSourceCentre.Connection = MDatabase.DatabaseConnection
  hForm.DataSourceCentre.Table = "centre"
  hForm.DataSourceCentre.Filter = "country_id = " & CountryId
  Print "hForm.DataSourceCentre.Filter = ", hForm.DataSourceCentre.Filter
  hForm.DataSourceCentre.Update()
  hForm.Refresh()
  hForm.DataBrowserCentre.Columns = ["centre", "country_id"]
  hForm.DataBrowserCentre.Labels = ["Centre", "CountryId"]
  hForm.DataBrowserCentre.Editable = True
  hForm.DataBrowserCentre.Update()
  hForm.DataBrowserCentre.SetFocus()
  hForm.Show() 
End

I have code for opening the form to do Centre maintenance;
Public Sub Form_Open()
  Print "FCentreMaintenance form opens"
  FMain.Hide()
  Me.Center()
  Print "FMain.ClearComboBoxCentre starting"
  FMain.ClearComboBoxCentre()
  FMain.ClearComboBoxLocation()
  Print "FMain.ClearComboBoxCentre finished"
End

However, I'm now getting an "Out of Bounds". 
The console is shown below. I can see that the form open code is finishing as normal.
Any ideas on how to debug this?
CountryId=      1
hForm.DataSourceCountry.Filter =        country_id = 1
hForm.DataSourceCentre.Filter =         country_id = 1
FCentreMaintenance form opens
FMain.ClearComboBoxCentre finished










More information about the User mailing list