[Gambas-user] Cant get DataCombo to work as expected...
benoit.minisini at gambas-basic.org
Wed Aug 30 21:33:59 CEST 2023
Le 30/08/2023 à 21:08, Martin Fischer a écrit :
> Hi to all,
> I'm currently playing around with gambas, tying to figure out if I could
> use it to create some little toolies for my personal need.
> I was quite familiar with VB6 back in the good old days, but well...
> long time ago. Nowadays I make my living as java backend dev.
> Now: I created a learing project with gambas that uses data-bound
> controls to display/edit a "person" table in a sqlite3 DB. Here is the
> relevant relational schema:
> person_id INT PK
> sex_id INT FK -> sex.sex_id
> given_name VARCHAR(80)
> sex_id INT PK
> name VARCHAR(80)
> Some rows as example:
> 1, 1, Martin, ...
> 2, 1, Juliane, ...
> 1 Male
> 2 Female
> Quite obvious what's going on here...
> I then created a gambase database project that uses a control hierarchy
> as follows:
> DataSource - attached to a Connection opened via code
> - bound to the "person" table
> DataControl for given_name
> DataCombo for sex_id
> This DataCombo has the following settings:
> - Table: sex
> - Field: sex_id
> - Display: name
> I understand that the underlying assumption of the DataCombo is that
> - the Field property specifies both the name of the column in the table
> of the parent datasource and the name of the pk column of the
> - there is a pk whith the name specified in the Field property in the
> lookup table
> This effectively enforces that these two columns have the same name.
> (And by the way, that there can not be two references to such a lookup
> table in the same table - which sometimes is a problem...)
> Anyway: my schema should be OK with this.
> Now: what happens is:
> - the DataCombo does not contain values to select from.
> Should be: all rows from the sex table: SELECT name from sex
> - the DataCombo shows the value of the sex_id column from the person
> Should be: the name column of the row in the sex table with the same
> sex_id value
> This example is so primitive that I'm surprised that it went wrong.
> Maybe I did not understand the meaning of the properties or the
> I would be pleased if someone could take the time to look into this.
> I'm sure that it's only a small detail that I might have missed.
> You find this project attached here. It is working except the faulty
> behaviour of the DataCOmbo.
> Thanks in advance.
> Martin Fischer
It's actually a very old buggy optimization from 2011.
To workaround it, you must not set DataSource.Connection last, after
having set the DataCombo properties (the problem may be the same for
other controls that needs a real refresh when the connection changes).
For example, just set DataCombo.Display property again after setting
DataSource Connection. It will internally force the DataCombo to refresh
itself with the new data from the new connection.
More information about the User