Previous | Index | Next 

[PRB] The data source of a bound control isn’t updated if the control’s value is modified via code

Most databound controls in VB Migration Partner library automatically update their data source when the input focus leaves the control (i.e. in their LostFocus event). However, in general controls don’t update their data source if their value is assigned programmatically.

To help you work around this behavioral difference, the VB6Form and VB6UserControl classes expose a custom UpdateDataSource method, which is meant to be called after a series of assignments to the bound property of a group of controls. The UpdateDataSource method receives an optional argument, i.e. the control whose data source must be updated; if you omit this argument, all the bound controls on the form or usercontrol’s surface are forced to update their data source.

It is convenient to add the call to UpdateDataSource method by means of an InsertStatement pragma:

        Private Sub cmdSave_Click()
            ' copy values from variables to bound controls
            txtName.Text = strName
            txtAddress.Text = strAddress
            txtCity.Text = strCity
            ' in VB6 the data source would be automatically updated, 
            ' whereas in VB.NET it is necessary to force the update
            '## InsertStatement Me.UpdateDataSource()
        End Sub

The VB6Data, VB6RemoteData, and VB6ADODC controls also expose the UpdateDataSource method, which iterates over all the controls that are bound to that specific data control. This method is more convenient if the parent form or usercontrol contains multiple data controls.

        ' Update the data source for all controls bound to the ADODC1 data control
        '## InsertStatement ADODC1.UpdateDataSource()

 

Previous | Index | Next