Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to default myGrid.columns.myobjects to my own?
Message
De
17/01/2000 08:42:34
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00318908
Message ID:
00318914
Vues:
27
Hi Eric.

>> I subclassed each foxpro object to my own. However, when I select mygrid, each object within the columns are the fox default ones.
Is it possible to change it ? Maybe by modifying the grid builder, if possible ? <<

You can modify the gridbuilder to do this, but it is not a trivial task. If you unzip HOME()+Tools\XSource\XSource.zip and check out vfpSource\Builders\GridBldr\GridBldr.vcx, you will see what I mean. It is probably easier to roll your own. This one should do the job, but you have to have the grid's ColumnCount, RecordSource, and Column ControlSources set up before you run it.
LPARAMETERS tuParam1, tuParam2, tuParam3
LOCAL llStyle, lnCnt

*** Location of the Library containing the Grid TextBox Class
#DEFINE	LOC_CLASSLIB	 SYS(5) + "\COMMON\Classes\Grids"
#DEFINE	LOC_PROC	SYS(5)+"\COMMON\Progs\OtherClasses"

IF ASELOBJ(aObj)=0
	MESSAGEBOX( 'Please Select A Grid & Re Run This Builder!' )
	RETURN
ENDIF

*** Force Grid to Standard Style
MakeStyle(aObj[1])

*** Loop thru columns
CREATE CURSOR curGridCols (;
	Name       C( 20), ;
	Caption    C( 40), ;
	ContSource C( 50), ;
	Width      N(  5), ;
	Movable    L(  1), ;
	Resizable  L(  1), ;
	Sparse     L(  1), ;
	ReadOnly   L(  1) )
														
FOR lnCnt = 1 TO aObj[1].ColumnCount
	INSERT INTO curGridCols VALUES ( ;
			ALLTRIM(aObj[1].Columns[lnCnt].Name), ;
			ALLTRIM(aObj[1].Columns[lnCnt].Controls[1].Caption), ;
			ALLTRIM(aObj[1].Columns[lnCnt].ControlSource), ;
			aObj[1].Columns[lnCnt].Width, ;
			aObj[1].Columns[lnCnt].Movable, ;
			aObj[1].Columns[lnCnt].Resizable, ;
			aObj[1].Columns[lnCnt].Sparse, ;
			aObj[1].Columns[lnCnt].ReadOnly )
NEXT

GO TOP
BROWSE NORMAL

*** If esc - confirm discard
IF LASTKEY()=27 AND MESSAGEBOX( 'Discard Changes ?', 4+32 ) = 6  && yes
	WAIT WINDOW NOWAIT "Discarded..."
	IF USED('curGridCols')
		USE IN curGridcols
	ENDIF
	RETURN
ENDIF

*** Update columns
lnCnt = 1
SCAN
	IF aObj[1].Columns[lnCnt].Controls[1].Caption != ALLTRIM(Caption)
		aObj[1].Columns[lnCnt].Controls[1].Caption = ALLTRIM(Caption)
	ENDIF
	IF aObj[1].Columns[lnCnt].ControlSource != ALLTRIM(ContSource)
		aObj[1].Columns[lnCnt].ControlSource = ALLTRIM(ContSource)
	ENDIF
	IF aObj[1].Columns[lnCnt].Sparse != Sparse
		aObj[1].Columns[lnCnt].Sparse = Sparse
	ENDIF
	IF aObj[1].Columns[lnCnt].ReadOnly != ReadOnly
		aObj[1].Columns[lnCnt].ReadOnly = ReadOnly
	ENDIF
	IF aObj[1].Columns[lnCnt].Width != Width
		aObj[1].Columns[lnCnt].Width = Width
	ENDIF
	IF aObj[1].Columns[lnCnt].Movable != Movable
		aObj[1].Columns[lnCnt].Movable = Movable
	ENDIF
	IF aObj[1].Columns[lnCnt].Resizable != Resizable
		aObj[1].Columns[lnCnt].Resizable = Resizable
	ENDIF
	IF aObj[1].Columns[lnCnt].Name != Name
		aObj[1].Columns[lnCnt].Name = "col"+ALLTRIM(name)
		aObj[1].Columns[lnCnt].Controls[1].Name = "hdr"+ALLTRIM(name)
		aObj[1].Columns[lnCnt].Controls[2].Name = "txt"+ALLTRIM(name)
	ENDIF
	lnCnt = lnCnt + 1
ENDSCAN

IF USED('curGridCols')
	USE IN curGridcols
ENDIF

********************************************************************
FUNCTION MakeStyle( toGrid )
	LOCAL llIS, lnCnt
	*** Find classlib and procedure file
	SET CLASSLIB TO LOC_CLASSLIB ADDITIVE
	SET PROCEDURE TO LOC_PROC ADDITIVE
	
	*** Set grid properties
	toGrid.ResetToDefault('DeleteMark')
	toGrid.ResetToDefault('FontBold')
	toGrid.ResetToDefault('FontSize')
	toGrid.ResetToDefault('HeaderHeight')
	toGrid.ResetToDefault('Panel')
	toGrid.ResetToDefault('RecordMark')
	toGrid.ResetToDefault('Visible')

	*** Set each column + header + textbox if it hasn't been set yet
	IF toGrid.Columns[1].Controls[1].Class = 'Header'
		FOR lnCnt = 1 TO toGrid.ColumnCount
			*** Remove them
			toGrid.Columns[lnCnt].RemoveObject( toGrid.Columns[lnCnt].Controls[1].Name )
			toGrid.Columns[lnCnt].RemoveObject( toGrid.Columns[lnCnt].Controls[1].Name )
			*** Add new ones
			toGrid.Columns[lnCnt].AddObject( 'hdrBase1', 'hdrbase' )
			toGrid.Columns[lnCnt].AddObject( 'txtgrd1', 'txtgrid' )
		ENDFOR
	ENDIF
ENDFUNC
Or you can wait until the our book is published by Hentzenwerke sometime this spring <g>.

Marcia
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform