Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Losing grid formatting
Message
De
04/03/2006 14:04:05
 
 
À
27/02/2006 14:13:30
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01099587
Message ID:
01101508
Vues:
19
Hi again,

seems everybody here is convinced that it's not possible to preserve grid layout, code & the like when recreating the underlying cursor.

Too hold against that here's an example that works just fine for me on VFP9 (and should work also on every older version):
loForm = CREATEOBJECT('oGridTest')
loForm.Show()

DEFINE CLASS basegrid AS Grid
	FUNCTION SaveBindings()
		LOCAL loCol
		THIS.AddProperty('OriginalRecordSource',THIS.RecordSource)
		FOR EACH loCol IN THIS.Columns
		 loCol.AddProperty('OriginalControlSource',loCol.ControlSource)
		ENDFOR
	ENDFUNC

	FUNCTION Lock()
		LOCAL loCol
		THIS.RecordSource = ""
		FOR EACH loCol IN THIS.Columns
		 loCol.ControlSource = ""
		ENDFOR
	ENDFUNC

	FUNCTION Unlock()
		LOCAL loCol
		THIS.RecordSource = THIS.OriginalRecordSource
		FOR EACH loCol IN THIS.Columns
		 loCol.ControlSource = loCol.OriginalControlSource
		ENDFOR
	ENDFUNC
ENDDEFINE

DEFINE CLASS oTestButton AS CommandButton
	Caption = "Recreate cursor"
	
	FUNCTION Click
		THISFORM.oGrid.Lock()
		USE IN SELECT('testalias')
		CREATE CURSOR testAlias (field1 M, field2 C(254))
		INSERT INTO testAlias VALUES (REPLICATE('Foo'+CHR(13),10),'Foo')
		INSERT INTO testAlias VALUES (REPLICATE('Bar'+CHR(13),10),'Bar')
		INSERT INTO testAlias VALUES (REPLICATE('Foo'+CHR(13),10),'Foo')
		INSERT INTO testAlias VALUES (REPLICATE('Bar'+CHR(13),10),'Bar')
		LOCATE
		THISFORM.oGrid.Unlock()
		THISFORM.Refresh()
	ENDFUNC
ENDDEFINE

DEFINE CLASS oTestEditBox AS EditBox
	Margin = 0
	BorderStyle = 0
	
&& too show that code from custom controls is not lost
	FUNCTION DblClick()
		MESSAGEBOX('Foobar')
	ENDFUNC
ENDDEFINE

DEFINE CLASS oGridTest AS Form

	Width = 500
	Height = 500
	WindowType = 1
	
	ADD OBJECT oGrid AS basegrid WITH Left=10, Top = 10, Height = 350, Width = 400
	ADD OBJECT oButton AS oTestButton WITH Left=10, Top = 400, Height = 50, width = 100
	
	FUNCTION Load
		CREATE CURSOR testAlias (field1 M, field2 C(254))
		INSERT INTO testAlias VALUES (REPLICATE('Foo'+CHR(13),10),'Foo')
		INSERT INTO testAlias VALUES (REPLICATE('Bar'+CHR(13),10),'Bar')
		INSERT INTO testAlias VALUES (REPLICATE('Foo'+CHR(13),10),'Foo')
		INSERT INTO testAlias VALUES (REPLICATE('Bar'+CHR(13),10),'Bar')
		LOCATE		
	ENDFUNC
	
	FUNCTION Init
		WITH THIS.oGrid
			.ColumnCount = 2
			.RecordSource = 'testalias'
			&& bind column 1 to field no. 2
			.Columns(1).ControlSource = 'testalias.field2'
			&& vice versa -> to show that fieldorder doesn't matter
			WITH .Columns(2)
				.AddObject('Edit1','oTestEditBox')
				.RemoveObject('Text1')
				.CurrentControl = 'Edit1'
				.Edit1.Visible = .T.
				.ControlSource = 'testalias.field1'
				.DynamicBackColor = 'IIF(testalias.field1="Foo",RGB(255,0,0),RGB(0,255,0))'
				.Sparse = .F.
			ENDWITH
		ENDWITH

		THIS.oGrid.SaveBindings()		
	ENDFUNC

ENDDEFINE
Regards
Christian
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform