Grid is the most strange object in VFP, but the most hard to use.
First of all, to do not allow to disappear you own controls from grid (to do not allow to rebuild grid automatically), you should never close alias when it is active in grid.
In other words, following lines will solve your problem:
thisform.MyGrid.RecordSource = "" && clear it so columns not lost when requery
* mare data query/refreshing
use in myAlias
SELECT .... ;
into cursor MyAlias
thisform.MyGrid.RecordSource = "MyAlias" && restore RecordSource
* restore column control sources, because VFP rearrange them
* NOTE - this is not needed if you're sure that order of fields in
* cursor match to order of columns in grid
thisform.MyGrid.Column1.ControlSource = "MyAlias.MyField1"
thisform.MyGrid.Column2.ControlSource = "MyAlias.MyField2"
...
>I am trying to setup a grid to display the results of a SQL using RecordSourceType=1. I also want the click of the headers to set the order of the SQL to that column. Unfortunatly, when I run the query, the grid loses sope of the cursor and the code in the headers (Click) is lost. I see that there is a RecordSourceType=4 (SQL) but there is NO documentation on it. It seems to me that using RecordSourceType=4 would allow me to change the Group By in the SQL without losing the cursor.
>
>Any Ideas?
>
>Thank you.
>
>Todd Cottengim
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.comICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs
It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.