Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grids and SQL Server
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01223538
Message ID:
01225441
Vues:
14
>I'm running into a weird issue and I just can't seem to track it down.
>
>I've got a form with two grids on it. In the Load() event of the form, I instanciate an object which connects to SQL Server, and pulls down two different cursors. One grid shows the parent records, the other grid shows the children for the selected parent. In the AfterRowColChange event, I refresh the child cursor from SQL server. As expected, this blows away the RecordSource of the child grid.
>
>I've got two methods in my grid classes to save/restore this info to handle this issue, and I usually have code that looks like this:
>
>
>ThisForm.grdDetail.SaveSource()
>
>ThisForm.oBizObj.GetDetail()
>
>ThisForm.grdDetail.RestoreSource()
>
>
>However, in this case, as soon as the SQLEXEC is run in the GetDetail() method (well, in my SQL object called by this method), it blows away the RecordSource for the Parent grid. If I check the code, it's definitely only refreshing the detail cursor. If I check the records in the parent cursor, they're still all there (so this cursor isn't getting closed).
>
>I created a simple form to see if I could reproduce the problem w/the base classes. I thought it may have something to do with the length of the cursor name, so I shortened it up to under 10 characters. It suddenly started working. So I changed it back to the longer name. It still works. I tried the same on my real form w/no luck.
>
>I've tried a default datasession vs a private datasession form, w/no difference. I can run each form back to back, one will work, the other will fail (I'd think if it were environment settings it would show up here).
>
>I created a
>
>BTW - I'm just using the terms parent/child to make this a bit easier to understand. There isn't any relationship set-up in the grid or via SET RELATION.
>
>Any thoughts or ideas?

Paul,

Since my early work with SQL Server data I use a GridProtector object
**************************************************
*-- Class:        gridprotector (c:\cdbk30\common30\libs\cutils.vcx)
*-- ParentClass:  ccustom (c:\cdbk30\common30\libs\ccontrls.vcx)
*-- BaseClass:    custom
*-- Time Stamp:   01/17/05 03:33:11 PM
*
#INCLUDE "c:\cdbk30\common30\include\framincl.h"
*
DEFINE CLASS gridprotector AS ccustom


	lrestore = .T.
	Name = "gridprotector"
	ogrid = .F.
	calias = .F.
	cdummyalias = .F.
	DIMENSION acontrolsources[1,1]


	PROCEDURE setdummyalias
		THIS.oGrid.RecordSource = 0 
	ENDPROC


	PROCEDURE setgrid
		LPARAMETERS toGrid
		THIS.oGrid = toGrid
		THIS.cAlias = toGrid.RecordSource
	ENDPROC


	PROCEDURE restorealias
		THIS.oGrid.RecordSource = THIS.cAlias
		THIS.oGrid.Refresh
	ENDPROC


	PROCEDURE setcontrolsources
		WITH THIS.oGrid
			DIMENSION THIS.aControlSources[ .COLUMNCOUNT]
			FOR lnColumn=1 TO .COLUMNCOUNT
				THIS.aControlSources[lnColumn]=.COLUMNS(lnColumn).CONTROLSOURCE
				.COLUMNS(lnColumn).CONTROLSOURCE=[]
			ENDFOR
		ENDWITH
	ENDPROC


	PROCEDURE restorecontrolsources
		WITH THIS.oGrid
		   FOR lnColumn=1 TO .COLUMNCOUNT
		      .COLUMNS(lnColumn).CONTROLSOURCE=THIS.aControlSources[lnColumn]
		   ENDFOR
		ENDWITH
	ENDPROC


	PROCEDURE restore
		THIS.RestoreAlias()
		THIS.RestoreControlSources()
		THIS.RestoreScrollbar()
	ENDPROC


	PROCEDURE set
		LPARAMETERS toGrid
		THIS.setGrid( toGrid)
		THIS.setControlSources()
		THIS.setDummyAlias()
	ENDPROC


	PROCEDURE restorescrollbar
		WITH THIS.oGrid
			.doScroll(2)
			.doScroll(2)
			.doScroll(2)
		ENDWITH
	ENDPROC


	PROCEDURE Destroy
		WITH THIS
			IF TYPE("THIS.oGrid")='O'
				IF .lRestore
					.Restore()
				ENDIF
			ENDIF
    			.oGrid = NULL
		ENDWITH
		RETURN DODEFAULT()
	ENDPROC


	PROCEDURE Init
		LPARAMETERS toGrid
		IF PCOUNT()=1
			THIS.set( toGrid )
		ENDIF
	ENDPROC


ENDDEFINE
*
*-- EndDefine: gridprotector
**************************************************
You can call it this way, say before requerying:
LOCAL loGridProtector
loGridProtector = CREATEOBJECT('GridProtector')
this.protectGridWith( loGridProtector )
When working with remote data you reconstruct a cursor at every requery. The grid looses its controlsource and by there its properties...

The {{{GridProtector}}} object is called in the requery() of remote data and saves the controlsources. The other properties are saved at the moment when this.recordsource = 0.


When the Requery() finishes the object {{{GridProtector}}} goes away and in its destroy() makes all the reconstruction work.

Warning: the implementation is not done for other objects that the grid might contain like combos. In this case, threat them manually.
PresentationChildObj.Requery()

LOCAL loGridProtector, loLockScreen
loLockScreen = CREATEOBJECT("Elockscreen")
loGridProtector = CREATEOBJECT('GridProtector', THIS.cGrid1)

lnRetval = DODEFAULT()

THIS.cGrid1.Column10.Bound = .t.

THIS.cGrid1.Column9.Bound = .F.
THIS.cGrid1.Column9.ControlSource = 'v_Presentation.NU_cCompteComptable'
THIS.cGrid1.Column9.cbocompteforpresentation1.ControlSource = 'v_Presentation.FK_iCompteId'

THIS.cGrid1.Column11.Bound = .F.
THIS.cGrid1.Column11.ControlSource = 'v_Presentation.NU_cQualiteInterne'

THIS.cGrid1.Column11.cboqualiteinterne1.ControlSource = 'v_Presentation.FK_iQualiteInterneId'
RETURN lnRetval
The credits go to Claudio Campos.

Hope this helps,
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform