[Gambas-user] Cant get DataCombo to work as expected...

Benoît Minisini benoit.minisini at gambas-basic.org
Wed Aug 30 23:21:24 CEST 2023

Le 30/08/2023 à 22:30, Martin Fischer a écrit :
>> 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.
> Thanks Benoit,
> I can confirm that my problem gets solved by executing
>    DataCombo.Display = DataCombo.Display
> right after setting the Connection on the DataSource.
> I also can confirm that using a static (predefined) connection
> as Datasource.Connection works *without*
>    DataCombo.Display = DataCombo.Display
> You mentioned that other data controls might be affected by this bug as
> well. This raises the question, how to handle this issue properly when a
> static connection is not an option.
> In my example project, I created a connection programmatically in the
> Form_Open() event handler. This obviously is too late.
> My goal would be to create a connection very early in the lifecycle
> of the application (before the data controls get initialized) and set it
> then as Db.Current so that the data controls do not suffer from a swap
> of the underlying connection. This would hopefully circumvent these
> problems.
> Do you know a means to do this?
> Regards
> Martin

Connect to the database in the Main() function of a startup class that 
is not a form. Once done, show your initial form.


Benoît Minisini.

More information about the User mailing list