Microsoft KB Archive/131213

= A grid loses its data when a list box or combo box on a form uses the Requery method in Visual FoxPro =

Article ID: 131213

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q131213



SYMPTOMS
Microsoft Visual FoxPro lets list boxes, combo boxes, and grids within a form to be based on the output of a query (.QPR) file. The list box and combo box controls support a Requery method. The Requery method causes the query to be updated. The grid does not support a Requery method to update the results of a query. Therefore, if the list box or combo box and the grid are populated with the results of the .QPR file, the grid loses its data when the Requery method is used on the list box or combo box.



RESOLUTION
Set the RecordSource property of the grid back to itself as shown in the following code: Thisform.Grid1.RecordSource = Thisform.Grid1.RecordSource Notes
 * For an example, see step 7 in the "Steps to reproduce the behavior" section.
 * By changing the RecordSource property of the grid, all the properties of the grid and its columns are set back to their default values. If you must save custom properties of the grid, follow the workaround that is described in the "References" section.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Open the C:\Vfp\Samples\Mainsamp\Data\Tastrade.dbc database. Create a new form named Frmmyfrm.  Add a list box to the form. Set the following properties in the properties sheet: List1.RowSourceType = 4 (QPR) List1.RowSource = qryTest.qpr   Add a grid to the form. Set the following properties in the properties sheet: Grid1.RecordSourceType = 3 (QPR) Grid1.RecordSource = qryTest.qpr  Add two command buttons to the form. Set the caption of the first button to "List Requery", and the caption of the second to "Grid RecordSource".  Add the following code to the Click event of the List Requery command button: Thisform.List1.Requery </li>  Add the following code to the Click event of the Grid RecordSource command button and to the Activate event of the form: Thisform.Grid1.RecordSource = Thisform.Grid1.RecordSource Note This command does not need to be in the Activate event of the form in Visual FoxPro 3.0 but is needed in Visual FoxPro 5.0. </li>  Close and save the form, create a new program file with the following code, save this file as Qrytest.qpr, and then close the file. SELECT contact_name, customer_id FROM customer INTO CURSOR curTest

** Use this code in Visual FoxPro 6.0 and later: SELECT contact, cust_id FROM customer INTO CURSOR curTest Note Make sure that you add the .qpr file name extension to the file. </li>  Enter the following command in the FoxPro Command window: DO FORM frmmyfrm </li>  Click the List Requery button and note that the data in the grid disappears. Click the Grid RecordSource button and the data reappears.

Note Do not base your grid on a .QPR file if the data in the grid needs to be modified. Data created with a .QPR file is read-only. Creating a view would be a better alternative if data needs to be modified. This requires setting the RecordSourceType of the grid to "2 - Alias" and the RecordSource to the name of the view. The data in the grid could then be refreshed using the REQUERY function. This is a Visual FoxPro function that can be issued on a command line by itself. The function should be preceded by an equal sign, as in the following example, to update the view with new data: =REQUERY </li></ol>

<div class="references_section">