This is the way to do it:
lsSQL = "Select Field1, Field2 from mytable into cursor tmpCursor2 readwrite order by 1"
&lsSQL.
select TempCursor
append from dbf('tempcursor2')
yourgrid.Refresh()
Note that with this solution you never change the grid's source-
>In VFP8 it works flawless. In VFP9, it is sometimes problematic and shouldn't be.
>
>Here's an example:
>
>
>with this
> lsSQL = "Select Field1, Field2 from mytable into cursor tmpCursor readwrite order by 1"
> .RecordSource = ''
>
> &lsSQL.
>
> .RecordSource = 'tmpCursor'
> .grcColumn1.ControlSource = 'tmpCursor.Field1'
> .grcColumn2.ControlSource = 'tmpCursor.Field2'
>
> .Refresh()
>
>Endwith
>
>
>
>
>
>>How detailed is the code that sets the grid properties? I do the same but dont have a problem (VFP8). With combos in columns, i've found that the order of setting the props is important.
>>
>>
>>WITH thisform.GrdFloor
>> .columncount = 16
>> .recordsource = "tmpfloor"
>> .column1.controlsource = "tmpfloor.fn_room"
>> .column2.ComboCeiling.ColumnCount = 1
>> .column2.ComboCeiling.ColumnWidths = "120"
>> .column2.ComboCeiling.ColumnLines = .t.
>> .column2.ComboCeiling.DisplayCount = 6
>> .column2.ComboCeiling.rowsourcetype = 3
>> .column2.ComboCeiling.rowsource = "SELECT floortype FROM floo...."
>> .column1.width = 120
>> .column1.fontsize = 8
>> .column1.readonly = .f.
>> .column1.enabled = .t.
>> .column1.movable = .f.
>> .column1.resizable = .f.
>> .column1.header1.caption = "Room"
>>ENDWITH
>>
>>
>>>I've done the following since VFP7 and it has always worked. Now it sometimes doesn't. The error I'm getting is that the first column doesn't exist where prior to the RecordSource being set to '' it did.
>>>
>>>1. I set up my grid (including columns, etc) without a recordsource (almost all of them are this way)
>>>2. I have a populate method on my grid to be called that executes a query that sets up the sorting etc and attaches the recordsource to the grid.
>>>3. In this Populate method, I do the following:
>>>
>>>
>>>this.Recordsource = ''
>>>{Execute sql statement here}
>>>this.RecordSource = 'MyCursor'
>>>
>>>{reset Controlsources for Columns}
>>>this.Refresh()
>>>
>>>
>>>Now most of my grids still work, but I'm having a few that refuse to follow. I've checked everything to ensure that the problematic ones are setup the same as the ones that work. No differences except columns. I'm trying to avoid redoing the problematic grids.
>>>
>>>TIA
>>>
>>>Richard