Microsoft KB Archive/131836

= A refreshed grid does not display any data when a cursor is updated at run time in Visual FoxPro =

Article ID: 131836

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh
 * 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 Q131836



SYMPTOMS
In Microsoft Visual FoxPro, if the RecordSource property of a grid is set to a cursor and then that cursor is updated at run time by using a "SQL Select Into Cursor " command, the grid does not display any data even if you refresh it by using the ThisForm.Refresh command or the '''ThisForm. .Refresh''' command.



CAUSE
When you execute a SQL Select statement into the same cursor specified in the RecordSource property of the grid, the original cursor must be destroyed before the new cursor can be created. When this occurs, the grid columns and the RecordSource are also cleared and then re-created. The record source of the grid is set to the new cursor, and the grid automatically creates columns. The new grid is working from scratch. Therefore, it does not load the data from the cursor.



RESOLUTION
To refresh the grid in this situation, set the RecordSource property of the grid to itself as in this example: thisform.grid1.recordsource=thisform.grid1.recordsource



STATUS
This behavior is by design.



MORE INFORMATION
For more information, click the following article number to view the article in the Microsoft Knowledge Base:

140653 A cursor-based grid is blank if the SELECT-SQL command resets the cursor in Visual FoxPro

Steps to reproduce the behavior
 Create a form, and then add the CUSTOMER.DBF table (in the \VFP\SAMPLES\DATA directory) to the Data Environment.  Place the following code in the Load event of the form: CREATE CURSOR Compdisp (company c(40),city c(15),country c(15))   Place the following code in the Destroy event of the form: SELECT Compdisp USE   Create a grid on the form, and give the grid the following property settings: ColumnCount=3 RecordSourceType=Alias RecordSource=Compdisp  Add a text box to the form.</li>  Add a command button with the following code in its Click event: SELECT company,city,country; FROM customer; WHERE customer.country=thisform.text1.value; INTO CURSOR Compdisp THISFORM.GRID1.REFRESH </li> Run the Form. Type France in the text box, and then click the command button.</li></ol>

The grid should display all records where Customer.Country="France," but it doesn't. The grid is blank. THISFROM.GRID1.REFRESH does not seem to update the grid. This happens even if the Cursor is not created in the Load event of the Form.

To have the grid display the data correctly, place the following command as the last line of code for the Click event of the command button: ThisForm.Grid1.RecordSource =ThisForm.Grid1.RecordSource

Keywords: KB131836

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.