Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Pete Sass
  Where is Pete Sass?
 Marathon, Ontario
 Canada
 Pete Sass
 To: stuart andrew
  Where is stuart andrew?
 Bristol
 United Kingdom
 stuart andrew
 Tags
Subject: RE: What causes grid reconstruction?
Thread ID: 331374 Message ID: 331443 # Views: 37 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Grids
Date: Thursday, December 29, 2011 10:38:44 PM         
   


> Hi Foxite, I have a form with a grid and i know that using another select causes grid reconstruction but i was wondering if the way it is currently done also does.
>
> On the grid init i set the grid recordsource to a blank cursor, i then populate the cursor using append from (TempCursor) and then set the recordsource to the now not blank cursor again.
>
> Will this cause grid reconstruction?


Hi,

Grid reconstruction is caused mainly by closing and opening the table cursor that is in fact the bound RecordSource to your Grid object. So the goal is to ensure your Grid is bound to a RecordSource that is left alone and never changes, "only the recordset changes."

You need to be following the "Safe Select" method for your Grid populations.
This basically means that the cursor that actually displays your Grid records is bound to a cursor is static, that data inside this cursor may change, but this cursor is never closed and remains statically bound to your Grid. You never reset your recordsource for the Grid.
You perform your SQL Select to a temp cursor first.
Then you access your Cursor that is bound to your Grid and Zap it.
Then you append from the temp cursor into the Cursor bound to your Grid and refresh the Grid.

Below is an example of this in a multi-user scheduling program I coded and this code is only to populate the Grid using the "Safe Select" method:

* --- Populate Grid1.
Line 1: SELECT EVENTS
Line 2: SELECT EVENTID, TITLE, STARTTIME, ENDTIME, DESC FROM EVENTS ORDER BY ORDER,DATE WHERE DATE = p_GetDate AND USERID = p_UserID INTO CURSOR curGrid1Events
Line 3: SELECT GRIDEVENTS
Line 4: ZAP IN GRIDEVENTS
Line 5: APPEND FROM DBF('curGrid1Events')
Line 6: SELECT GRIDEVENTS
Line 7: GOTO TOP
Line 8: Thisform.Grid1.Refresh


Now in the above code lets dissect this simple code example ....
1. EVENTS is my main schedule Events table, but this is not bound to the Grid as a RecordSource.
2. I do have a table called GRIDEVENTS this is in fact bound to my Grid as a RecordSource and I have exclusive access over this table as set in the data environment of the form in the DA at the cursor level.
3. I perform a SELECT statement as shown above in Line 2: to a local cursor called curGrid1Events. In this example, some WHERE conditions do apply to the select statement, so you can modify things here to show what you want to display.
4. Now I can select my Grid bound table called GRIDEVENTS shown above under Line 3:
5. Now I can Zap the contents of the records in the table GRIDEVENTS as shown above under Line 4:
6. Now I can append from my local cursor containing the new records I want to display as shown above under Line 5:
7. Now I select my newly populated table called GRIDEVENTS as shown above under Line 6:
8. Now I issue a GOTO top command to ensure I see all the records starting at the top of the recordset.
9. Finally I refresh my Grid so I see the new recordset I wish to display within the Grid.

Notice how the real table bound to the Grid "GRIDEVENTS" is never closed or re-opened or re-referenced as a RecordSource.

So you have in fact created a buffer type of scenario between the read table holding all the raw data called "EVENTS" and the table that is in fact bound to your Grid object and what the user actually sees in the Grid looking at the GRIDEVENTS table.

I hope for those of you who are not familar with the "Safe Select" approach, this now de-mystifies this for you all.

There are many variations of using the "Safe Select" method to populate Grids, this is just one of them....

Pete "the IceMan", from the Great White North of Canada.
www.marathongriffincomputers.com

ENTIRE THREAD

What causes grid reconstruction? Posted by stuart andrew @ 12/29/2011 1:45:28 PM
RE: What causes grid reconstruction? Posted by anand kulkarni @ 12/29/2011 1:53:46 PM
RE: What causes grid reconstruction? Posted by stuart andrew @ 12/29/2011 1:56:45 PM
RE: What causes grid reconstruction? Posted by anand kulkarni @ 12/29/2011 1:58:03 PM
RE: What causes grid reconstruction? Posted by tushar @ 12/29/2011 2:58:22 PM
RE: What causes grid reconstruction? Posted by Pete Sass @ 12/29/2011 10:38:44 PM
RE: What causes grid reconstruction? Posted by Anders Altberg @ 12/30/2011 1:34:29 AM
RE: What causes grid reconstruction? Posted by Jun Tangunan @ 12/30/2011 2:34:31 AM