Microsoft KB Archive/260048

= PRB: Grid Becomes Empty When Changing DataSession =

Article ID: 260048

Article Last Modified on 5/10/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q260048



SYMPTOMS
When programmatically changing the DataSession property of a form, all rows of the grid become empty and appear deleted. This behavior can occur with a Private or Default data session form.



CAUSE
When programmatically changing a DataSession property on a form containing a grid, the grid loses its RecordSource property.



STATUS
This behavior is by design.



MORE INFORMATION
While it is not necessary that the form have a Private data session, multiple data sessions must exist so that the change can occur. For example, if there are two forms, Form1 (Private data session) and Form2 (Default data session), and the code on Form2 switches to the data session of Form1, the RecordSource property of the Form2 is reset to an empty string.

Steps to Reproduce Behavior
 Create new a form and set the DataSession property to 2 - Private Data Session. Add a table to the data environment of the form. Drag the table from the data environment to the form to create a grid. In the Properties window, make sure that the Name property for the grid is grid1.  Add a command button, Command1, and place the following code in the click event: LOCAL nDataSession, cRecordSource nDataSession = SET('datasession') SET DATASESSION TO 1 SET DATASESSION TO (nDataSession)  Save the form as Form1.</li> Run Form1 and click Command1. Note that all rows of the grid become empty and appear deleted.NOTE: To view the workaround, uncomment the two designated lines of code from &quot;Steps to Reproduce Behavior&quot; and re-run the the program. Note that the grid retains the RecordSource property and the data.</li></ol>
 * !* Uncomment the following line to view the workaround
 * !* cRecordSource = THISFORM.grid1.RECORDSOURCE
 * !* Uncomment the following line to view the workaround
 * !* THISFORM.grid1.RECORDSOURCE = cRecordSource

<div class="references_section">