Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Utility to rename grid columns according to Column Order
Message
De
03/11/2010 00:38:25
 
 
À
02/11/2010 11:20:35
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01487806
Message ID:
01487925
Vues:
57
Thanks Dragan.

It drives me crazy to have columns in the wrong order in the property sheet.

Alex



>>>>If somebody would share a utility to rename and reorganize grid columns according to ColumnOrder I'd be much obliged.
>>>>
>>>>In other words so that the column with ColumnOrder = 9 is has name = "Column9" and appears between Column8 and Column10.
>>>>
>>>>TIA,
>>>>
>>>>Alex
>>>
>>>Check Re: Keytrapping in a Grid Thread #679588 Message #679620 and modify for your needs.
>>
>>That renames columns nicely. Thank you.
>>
>>Next I need to save the columns in name order in the scx file. In other words, bring them all to front (or is is back) in name order, except VFP doesn't offer that alternative.
>
>Here's my column swapper. You need to get a reference to the grid being edited, via aSelObj(), and then in command window pass this reference, number of the column to move, position to move it to. The position is in instantiation terms. It creates an additional column for you, copies PEMs from 1st column, then copies from 2nd to 1st, then from this new temp column to 2nd, then drops the temp column.
>
>So to call it
>
>do bldColSwap with oGrd, 4, 6
>
>and you get columns 4 and 6 swapped.
>
>
* bldColSwap.prg
>Lparameters og As Grid, nCol1, nCol2
>*[2005/05/09 14:01:59] ndragan - pass a reference to the grid and 
>* the numbers of columns to swap
>*[2009/07/07 14:02:36] ndragan - added "bld" to the name
>Local cName1, cName2
>og.AddColumn()
>og.Columns[og.ColumnCount].Name="coltemp"
>objclone(og.Columns[nCol1],og.coltemp)
>objclone(og.Columns[nCol2],og.Columns[nCol1])
>objclone(og.coltemp, og.Columns[nCol2])
>cName1=og.Columns[nCol1].Name
>cName2=og.Columns[nCol2].Name
>og.Columns[nCol1].Name = Sys(2015)
>og.Columns[nCol2].Name=cName1
>og.Columns[nCol1].Name=cName2
>og.RemoveObject("coltemp")
>
>*---------------------------------------------------
>Procedure objclone(o1 As Column, o2 As Column)
>*-- dn 13/06/04
>	Local c, o, N, i, l, cCRS, aProp[1,1], omember1 As TextBox, omember2
>
>* reset o2 to default
>	N=Amembers(aProp,o2,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 Proper(cWhatName)="Name"
>* do nothing, name is handled outside this procedure
>			Case Inlist(cWhat, "Property", 'Method' , 'Event')
>* whatever it is, try to remove it, we want the target object to lose personality
>				Try
>					o2.ResetToDefault(cWhatName)
>				Catch
>* do nothing, really
>				Endtry
>			Case cWhat="Member"
>				Try
>					o2.RemoveObject(cWhatName)
>				Catch
>* do nothing - it can't be removed because it is added at class level
>				Endtry
>		Endcase
>	Endfor
>
>* now copy all from o1 to o2
>* members first
>	N=Amembers(aProp,o1,2)
>	For i=1 To N
>		omember1=Evaluate("o1."+aProp[i,1])
>		If Type("o2."+aProp[i,1])#"O"
>			o2.Newobject(aProp[i,1],omember1.Class, omember1.ClassLibrary)
>		Endif
>		omember2=Evaluate("o2."+aProp[i,1])
>		objclone(omember1, omember2)
>	Endfor
>* and now copy all properties and code
>	N=Amembers(aProp,o1,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 Proper(cWhatName)="Name"
>* do nothing, name is handled outside this procedure
>			Case Inlist(cWhat, "Property")
>				If PemStatus(o2,cWhatName,5)
>					Store Evaluate("o1."+cWhatName) To ("o2."+cWhatName)
>				Else
>					o2.AddProperty(cWhatName, Evaluate("o1."+cWhatName))
>				Endif
>			Case Inlist(cWhat, 'Method' , 'Event')
>* whatever it is, try to convert into a string
>				o2.WriteMethod(cWhatName, o1.ReadMethod(cWhatName))
>			Case cWhat="Member"
>* remove it from the source object
>				o1.RemoveObject(cWhatName)
>		Endcase
>	Endfor
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform