Using VFP8...
I have a simple form with a grid. I want to use a cursor object to use as the record source for the grid so I can let the user change which column to sort on.
I Select and order the data and create the cursor (csrTemp) in the form.init, the view that is used in the Select is in the Data Environment.
I'm not sure how to reference the cursor in the data source for the grid, when I run the form it seems like the order is from the original view, even though if I browse the cursor (from the init) the cursor is populated and ordered as I requested.
These are my settings:
grid.recordsource = csrTemp
grid.recordsourcetype = 2 - Prompt (all other options give me an empty grid)
What would be the proper syntax settings
Thanks!!!

Cursors, Views, and Grids
DaveC#
Hi Greg.
I'm not sure how to reference the cursor in the data source for the grid, when I run the form it seems like the order is from the original view, even though if I browse the cursor (from the init) the cursor is populated and ordered as I requested.
The way that I do this is to create the grid's RecordSource in the form's Load and then use the cursor as the alias for the grid. Then when I want to change the soert order of the grid, I use code like this:
LOCAL llAllowCellSelection, lcFrom, lnBuffering
KEYBOARD '{CTRL+TAB}'
lcFrom = This.RecordSource + [ ORDER BY ] + This.cSortField + [ ] + This.cSortOrder + [ INTO CURSOR qTmp NOFILTER]
SELECT * FROM &lcFrom
SELECT ( This.RecordSource )
lnBuffering = CURSORGETPROP( "Buffering" )
IF lnBuffering > 3
*** Since we are in view mode, the grid's RecordSource should have
*** no pending changes, but if it does, they are spurious and
*** we can throw them away
TABLEUPDATE( 1, .F., This.RecordSource )
CURSORSETPROP( "Buffering", 3, This.RecordSource )
ENDIF
ZAP
APPEND FROM DBF( 'qTmp' )
GO TOP IN ( This.RecordSource )
CURSORSETPROP( "Buffering", lnBuffering, This.RecordSource )
USE IN qTmp
This.Refresh()
This.SetFocus()
Zapping the grid's RecordSOurce does not close it, so you aviod what Cetin calls "grid reconstructions". Also, if you are using cursors that are not updateable, this is very flexible and you can sort on any column in the grid.
amselem
Grids have an affinity to snap an alias they find if specified source is not available. This behavior also might lead to an action known as "grid reconstruction". Anyway it is a long subject and might lead to confusion.
1) Instead of init use load to select/create your cursor. Then you might directly specify the recordsource directly in PEM sheet (so when grid initializes the cursor would be available).
2) If you use form init then code it as (if grid has a formatting you want to keep):
with this.myGrid
.RecordSource = ""
* cursor preparation here or before
.RecordSource = "crsTemp" && If doing in code quotes are important
* optionally you might format columns programmatically here
endwith
3) Instead of selecting/creating or whatever the cursor, you might use:
RecordSourceType: 4 - SQL
RecordSource: select .... into cursor crsMyGrid
Note: If SQL is long PEM sheet have 255 chars limit. You might instead do this in code in grid.init or form.init (don't forget quotes when you do in code). If your SQL has parameters (ie: where cust_id == thisform.txtCustomer.Value) the code to "refresh" the grid is not refresh but:
with ...myGrid && whatever the object ref is
.RecordSource = .RecordSource
endwith
Final notes: If a grid is going blank (that's a total white space - I don't mean no records version) then check your recordsource and column controlsource settings. One of them would be invalid (ie: in your case it might that you were doing that in code and didn't have quotes, a vairable expression w/o parentheses ...).
Go to www.universalthread.com downloads section and search for "Two grid classes". Infamous MultiSelectGrid class is in that download and its source code might help you to better understand.