Microsoft KB Archive/140653

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

Article ID: 140653

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 5.0a
 * 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 Q140653



SYMPTOMS
In Microsoft Visual FoxPro, if the RecordSource property of a grid is set to a cursor, and then the SELECT-SQL command resets the cursor, the grid appears blank if the RecordSource property is not set back to itself.

The following command will refresh the grid properly if a SELECT-SQL is run to rebuild the cursor, but if the column or header properties of the grid have been customized, these customized changes will be lost and the column and header properties of the grid will change back to their default settings: THISFORM.GRID1.RECORDSOURCE=THISFORM.GRID1.RECORDSOURCE Such customization could be headers with different names, longer column lengths, and code placed in the events of columns or headers. For more information, please see the following article in the Microsoft Knowledge Base:

131836 PRB: Grid Not Refreshing Displaying a Cursor from Query



CAUSE
When you rebuild the cursor that the grid is based on with the SELECT-SQL command, the original cursor has to be destroyed before the new cursor can be created. When this happens, the grid columns and headers are also cleared and then recreated. Even when the RecordSource property of the grid is set back to itself, the custom settings of the columns and headers of the grid are lost.



RESOLUTION
To refresh the grid without losing the custom properties of the columns and headers, set the RecordSource property to a dummy cursor that already has been created with the same fields as the cursor the grid is based on. After the SELECT-SQL is run, change the RecordSource property back to the rebuilt cursor. This allows the properties of the columns and headers to remain intact while the cursor is being rebuilt.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Open the Customer.dbf table located in the \Vfp\Samples\Data directory, and create a form called GridForm.  Place the following code in the Load event of the form: SELECT cust_id, city, country FROM customer INTO CURSOR Temp1 SELECT cust_id, city, country FROM customer WHERE country = "" ; INTO CURSOR Temp2   Place the following code in the Destroy event of the form: SELECT Temp1 USE SELECT Temp2 USE   Place a grid on the form, and give the grid the following property settings: ColumnCount=3 RecordSourceType=Alias RecordSource=Temp1  Change the caption of the grid1.Column1.header1 to Customer Id and the Column1 Width property to 100.</li> Add a text box to the form.</li>  Add a command button, and place the following code in its Click event: THISFORM.GRID1.RECORDSOURCE = "Temp2" SELECT cust_id, city, country FROM customer ; WHERE country = Thisform.text1.value ; INTO CURSOR Temp1 THISFORM.GRID1.RECORDSOURCE = "Temp1" </li> Run the Form. Type Spain in the text box, and then click the command button. The grid should display all records where the country field is equal to Spain. Note that the name of the header of column 1 stays the same and the width of the column doesn't change. By changing the RecordSource of the grid to the cursor called Temp2, the properties of the columns and headers are not reset when the Temp1 cursor is rebuilt.</li>  Change the two THISFORM.GRID1.RECORDSOURCE lines in the Click event of the command button into comments and add the following as the last line of code: THISFORM.GRID1.RECORDSOURCE = THISFORM.GRID1.RECORDSOURCE After running the form, typing a country name in the text box, and clicking the command button, note that the column name changes and the width is smaller. </li></ol>

Additional query words: VFoxMac VFoxWin

Keywords: KB140653

-

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

© Microsoft Corporation. All rights reserved.