Microsoft KB Archive/216666

= PRB: DataBound Controls Not Updated with DataEnvironment Using Refresh Method =

Article ID: 216666

Article Last Modified on 8/16/1999

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q216666



SYMPTOMS
The DataCombo and DataGrid controls are not refreshed when using the Refresh method. This behavior is exhibited when using the DataEnvironment.



RESOLUTION
There are several workarounds. One is to use the ADO Data Control instead of the DataEnvironment. Another is to rebind the controls to the DataEnvironment.

The following code rebinds the controls. Replace the code in the Refresh Click event in the Steps to Reproduce Behavior section with the following:

Set DataGrid1.DataSource = DataEnvironment1 Set DataCombo1.DataSource = DataEnvironment1 Set DataCombo1.RowSource = DataEnvironment1



STATUS
This behavior is by design.



MORE INFORMATION
When running an application and then adding or updating data, the user may want to see the changes reflected in the DataCombo. However, when using the DataEnvironment, these changes are not seen without re-binding the control.

Steps to Reproduce Behavior
 Create a Standard EXE Project in Visual Basic. Form1 is created by default. From the Project menu, select Add Data Environment. Alternate-click Connection1 and choose Properties. Select Microsoft Jet 3.51 OLE DB Provider, click Next, and choose the Nwind.mdb database. Click OK. Alternate-click Connection1, and select Add Command. Next, alternate-click Command1 and select Properties. In the Database Object drop-down box, select Table, and, under Object name, select Customers. Click OK and the DataEnvironment is created. From the Project/Components menu, add the Microsoft DataGrid Control 6.0 and the Microsoft DataList Controls 6.0. On Form1, place a DataCombo control, a DataGrid control, and a Command Button. Rename the command button Refresh.</li> Set the DataSource and RowSource properties of the DataCombo to DataEnvironment1. Set the RowMember to Command1, and ListField property to CustomerID.</li>  Set the DataGrid Datasource to DataEnvironment1 and the DataMember to Command1. In the Refresh command button Click event, place the following code: ' Updates the recordset with the added data. DataEnvironment1.rscommand1.Requery

' Supposed to Refresh new data in the Datagrid DataGrid1.Refresh

' Should have updated the Combobox with the new data DataCombo1.ReFill DataCombo1.Refresh </li> Press the F5 key to run the code and look at the data in both the DataGrid and DataCombo. Pause the code and open the Nwind.mdb Customers table in Access and add a new CustomerID "ZZZZZ." Close the table and resume running the application in Visual Basic. Click the Refresh button to update, and note the DataGrid and the DataCombo do not show the new record.</li></ol>

<div class="references_section">