Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid utility to insert a column (in large grid)
Message
De
18/02/2015 03:31:42
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
17/02/2015 17:25:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01615507
Message ID:
01615509
Vues:
97
J'aime (1)
>Hi all,
>
>I am wondering if anyone has written a tool to insert a column into an already existing grid? This comes up the odd time when someone wants a mod to a grid and of course, they don't want the column added to the end of the grid but invariably somewhere close to the beginning. So it means adding the column and then laboriously moving the controls one by one.
>
>I think I have (in the past) hacked the .scx as I could open the appropriate record for the form and modified the properties of the grid. I think this is fairly safe but if I remember correctly, if you are changing the control within the column, you still have to do some other things.

Here's what I do... use this builder to generate all the columns from grid's .init(). Then it's a piece of cake to edit the code to have a column where you want it. Backup first, as this will remove your old grid and build a new one with all the code in its .init(). Select your grid and run this from the command window.
*[2004/04/30 15:48:05] ndragan - write the code to rebuild the grid in the grid's init.
*[2008/05/08 00:58:21] ndragan - assume a grid. of the same class/lib
*[2009/07/08 23:03:42] ndragan - added "bld" to the name so I can remember it.

N=ASELOBJ(aa)
IF N>0
	LOCAL og AS GRID, loGrd AS GRID, oParent AS CONTAINER
	og=aa[1]
	_PRETEXT=CHR(13)
	IF og.BASECLASS="Grid"
		oParent=og.PARENT
*[2008/05/08 00:58:21] ndragan - assume a grid. of the same class/lib
*		oParent.Newobject("grd","grd","ctls.vcx")
		lcTempGrd=SYS(2015)
		oParent.NEWOBJECT(lcTempGrd, og.CLASS, og.CLASSLIBRARY)
		loGrd=GETPEM(oParent, lcTempGrd)
		N=AMEMBERS(aProp,og,1,"UC")

		FOR j=1 TO N
			cWhat=aProp[j,2]			&& what is it - property, method, event, member
			cWhatName=aProp[j,1]	&& PEM name
			DO CASE
				CASE cWhat="Property" AND INLIST(PROPER(cWhatName), "Name", "Column")
* do nothing, name is handled in the end of the loop
				CASE cWhat="Property"
* whatever it is, try to convert into a string
					cProp=""
					cType=TYPE("oG."+cWhatName)
					IF cType#"U"
						cProp=EVALUATE("oG."+cWhatName)
					ENDIF
					IF PEMSTATUS(loGrd, cWhatName,5)
						STORE cProp TO ("loGrd."+cWhatName)
					ELSE
						loGrd.ADDPROPERTY(cWhatName, cProp)
					ENDIF
				CASE cWhat='Method' OR cWhat='Event'
					lcCode=og.READMETHOD(cWhatName)
					loGrd.WRITEMETHOD(cWhatName, lcCode)
			ENDCASE

		ENDFOR
		loGrd.COLUMNCOUNT=0
* Generate the code for the new grid's .init
* omitting the dodefault() because grd.init has code we don't need here
		TEXT textmerge noshow to lcInit
*
*	<<prog()>> generated <<datetime()>> <<sys(0)>>
*
		ENDTEXT
*
		FOR ii=1 TO og.COLUMNCOUNT
			WITH og.COLUMNS[ii]
*				lcColName="col"+Proper(Justext(.ControlSource))

				lcColName=.NAME
				lcCaption=.header1.CAPTION
				TEXT textmerge noshow to lcInit addi

* column <<ii>>
		This.Newobject("<<lcColName>>","column")
		With This.<<lcColName>>
				ENDTEXT
				DO writeprops WITH og.COLUMNS[ii]

				TEXT textmerge noshow to lcInit addi

			.Visible=.T.
Endwith

				ENDTEXT
			ENDWITH
		ENDFOR

* carry over any code already in init
		lcOldCode=og.READMETHOD("init")
		IF EMPTY(lcOldCode)
			lcOldCode="dodefault()"
		ENDIF
		lcInit=lcInit+CHR(13)+"*";
			+CHR(13)+"**** code from the old grid";
			+CHR(13)+lcOldCode
		nn=ALINES(al,lcInit,.T.)
		lcInit=""
		FOR ii=1 TO nn
			IF NOT EMPTY(al[ii])
				lcInit = lcInit + al[ii]+CHR(13)
			ENDIF
		ENDFOR
		loGrd.WRITEMETHOD("init", lcInit)
* now remove the new object as the old and remove the old button
		lcName=og.NAME
		oParent.REMOVEOBJECT(lcName)
		loGrd.NAME=lcName
	ENDIF
ENDIF

PROCEDURE writeprops(oObj)
	LOCAL N,j, cWhat, lcCode, cProp, aCProp[1]
	WITH oObj
		N=AMEMBERS(aCProp,oObj,1,"UC")
		FOR j=1 TO N
			cWhat=aCProp[j,2]			&& what is it - property, method, event, member
			cWhatName=aCProp[j,1]	&& PEM name
			DO CASE
				CASE cWhat="Property" AND INLIST(PROPER(cWhatName), "Name", "Column")
* do nothing, name is handled in the end of the loop
				CASE cWhat="Property"
* whatever it is, try to convert into a string
					cProp=""
					cType=TYPE("."+cWhatName)
					IF cType#"U"
						cProp=EVALUATE("."+cWhatName)
					ENDIF
*!*				If PemStatus(loGrd, cWhatName,5)
*!*					Store cProp To ("."+cWhatName)
*!*				Else
*!*					loGrd.AddProperty(cWhatName, cProp)
*!*				EndIf
					ASSERT NOT EMPTY(cProp)
					DO CASE
						CASE 			cType$"CM"
							cProp=["]+cProp+["]
						CASE cType="D"
							cProp="{^"+TRANSFORM(DTOS(cProp),"9999-99-99")+"}"
						CASE cType="T"
							cProp="{^"+TRANSFORM(ttos(cProp),"9999-99-99 99:99:99")+"}"
						OTHERWISE
							cProp=TRANSFORM(cProp)
					ENDCASE

					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

				.<<cWhatName>>=<<cProp>>
					ENDTEXT
				CASE cWhat='Method' OR cWhat='Event'
*!*				lcCode=.ReadMethod(cWhatName)
*!*				o2.WriteMethod(cWhatName, lcCode)
				CASE cWhat="Object"
					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

							With .<<cWhatName>>
					ENDTEXT
					DO writeprops WITH EVALUATE("."+cWhatName)
					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

							endwith
					ENDTEXT
			ENDCASE
		ENDFOR
	ENDWITH

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform