Microsoft KB Archive/132478

= PRB: Grid Column's CurrentControl Reverts to Text1 Default =

Article ID: 132478

Article Last Modified on 2/15/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q132478



SYMPTOMS
When you use the SQL SELECT command, and set the grid's RecordSource property to the newly queried cursor file, the grid column's current control (Check1 for example) reverts to Text1 (the default control).



CAUSE
The SQL SELECT code includes a SELECT ... INTO CURSOR TESTCURSOR command, which is the RecordSource for the grid. When this happens, the original cursor must be destroyed before the new cursor can be created. When the orginal cursor is destroyed, the grid columns and the controls in the columns are also destroyed, as well as the check box. In this case, the check box is destroyed. The SQL SELECT code sets the grid's RecordSource to the new cursor. At this point, the columns are automatically created with the default settings. There is no code to recreate the check box.



WORKAROUND
To retain the controls in the grid columns, add the following statement prior to executing the SQL SELECT command: THISFORM.Grid1.RecordSource = "" For more information, please see the example workaround in the More Information section of this article.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Issue the following commands: CREATE TABLE Testdbf (id N(1), region C(10)) INSERT INTO Testdbf VALUES (0, "North") INSERT INTO Testdbf VALUES (1, "South") INSERT INTO Testdbf VALUES (0, "North") INSERT INTO Testdbf VALUES (1, "South")  Create a form named Test. Add the Testdbf table to the Test form's Data Environment. Drag the Testdbf table to the form. A grid is added to the form.  Set the following PEMs (properties, events, and methods) for the grid: .ColumnCount = 2 .RecordSource = "testcursor" </li> Select Grid1.Column1 in the Properties window.</li> Click the check box tool on the toolbar. On the grid, Check1 should appear under Grid1.Column1 in the Properties window.</li> Change the Grid1.Column1.CurrentControl property to Check1.</li> Add a text box to the form.</li>  Add a command button to the form, and set the following PEMs: .Caption = "SQL" .Click SELECT * FROM Testdbf ; WHERE region = ALLTRIM(thisform.text1.value) ; INTO CURSOR testcursor THISFORM.Grid1.RecordSource = "testcursor" THISFORM.Grid1.SetFocus </li>  In the Form1.Load event, add this line of code: SELECT * FROM Testdbf WHERE region = "North" ; INTO CURSOR testcursor </li> Save and run form. The grid is populated with "North" records only, and Grid1.Column1 displays a check box.</li> Type South in the text box.</li> Click the SQL button.</li> Widen the ID column. The grid is populated with the "South" records only, and Grid1.Column1 no longer displays a check box control. It now displays the default control, which is a text box with a value of 1 for both records.</li></ol>

Example Workaround
<ol> Modify the Test form.</li>  In the Command1.Click event, add the following statement prior to executing the SQL SELECT command: THISFORM.Grid1.RecordSource = "" For example: THISFORM.Grid1.RecordSource = "" SELECT * FROM Testdbf ; WHERE region = ALLTRIM(thisform.text1.value) ; INTO CURSOR testcursor THISFORM.Grid1.RecordSource = "testcursor" THISFORM.Grid1.SetFocus </li> Type the CLEAR ALL command in the Command window.</li> Save and run the form.</li> Type South in the text box.</li> Click the SQL button. Now the grid is populated with the "South" records only, and Grid1.Column1 redisplays the check box control.</li></ol>

Additional query words: VFoxWin refresh

Keywords: kbcode KB132478

-

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

© Microsoft Corporation. All rights reserved.