Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Holding Nondefault Grid Control Methods

Status
Not open for further replies.

Headwinds

Programmer
Feb 6, 2001
38
US
Is there any way I can switch the RecordSource of a grid without losing nondefault grid controls? Failing that, is there any way I can programatically reestablish the methods of my nondefault grid controls after I've rebuilt them with AddObject() code?

I'm reengineering a VFP6 app (SQL Server back end) to eliminate remote views and replace them with passthrough queries. Many of the forms use a drop-down list box to navigate (e.g., from one county to another) and then display the results on a grid (e.g., census information for the selected county). The grids typically have some nondefault controls (spinners and/or drop-down list boxes) that are used for editing and adding records. An "undo" feature is implemented via table buffering.

When the grid's RecordSource was a remote view, the grid knew it was looking at the same remote view all the time, even when the view was requeried with new parameters. Now, I'm using as the RecordSource an updatable cursor that I load from a query result. I have to recreate the updatable cursor for each query in order to get rid of all of the data from the previous selection (e.g., previously selected county). This destroys the grid.

Setting the RecordSource equal to itself doesn't fix this, nor does setting it to another cursor that is structurally identical to the "real" RecordSource while it's being rebuilt and reloaded. The only solution I can think of is to move the navigation list box off to another form and call the grid form from it. That way, the context is fixed for the entire life of the grid--but this is not as slick as what the users are accustomed to seeing.

TIA for any ideas on this!
 
Here's the simplest solution:
Code:
myForm.myGrid.RecordSource=""
&& Code to requery the data source goes here
myForm.myGrid.RecordSource=cQueryTable
This will keep the grid intact, controls and all, but the field order in the query should match the field order in the grid. Otherwise, you'll have to iterate through each column and specify each one's ControlSource property after setting the grid RecordSource.
 
Not for me. When I try to use:

myForm.myGrid.RecordSource=""

I get "Fatal Error: Exception Code = C0000005" and FoxPro terminates. (I'm running VFP6.0 SP3 and Win2000, v.5 SP 2.)

If I try to change the RecordSource to any other cursor's name, I get the same result. The only RecordSource assignment that doesn't blow up FoxPro is setting the RecordSource to itself, but that doesn't help.
 
Two questions, where exactly are you trying to reset the grid's RecordSource? What are you using for a RecordSourceType? I use code like Ian provided in many applications running under all current OSs. Any reason you are still on SP3? Why not SP 4 or better yet 5?

Rick
 
try this instead - this is what I use--->>>>>>

thisform.recordsource=space(0)
 
Headwinds,

I would have to look at MSDN more carefully myself, but I believe a lot of C0000005 exceptions were fixed in service pack 5. I highly recommend you update. :eek:)
 
I'm trying to reset the grid's RecordSource in the InteractiveChange method of a drop down list box that is used to select a county. The RecordSource type is 1 (Alias). I've also got a bunch of these grid forms that work, but when I reengineer their RecordSource from remote views to updatable cursors, I'm getting the naughty behavior described above.

I'm going to try the SP 5 upgrade. Hope that fixes it. Unfortunately, the 75MB VFP version of the upgrade seems to be unavailable, so I'm going for the 133MB full VS download over a very slow phone connection.

Thanks everybody for your suggestions.
 
When you say "updatable Cursor", do you mean a true cursor (CREATE CURSOR cTemp ...), or are you playing the USE (dbf('myselect')) ... AGAIN "game" with the result of an SQL SELECT?

Good luck on the download, I've found that after 10:00 pm and before 8:00 am EST is the best time for getting big files from MS.

Rick
 
I'm making the updatable cursors with CREATE CURSOR cTemp (col1 type(size), etc.).

I forget to say in the previous post that

thisform.Grid1.recordsource=space(0)

didn't work any better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top