>*** Get the grid preferences for this grid >*** and restore the grid configuration >IF THIS.COLUMNCOUNT > 0 > *** Save settings at grid instantiation > THIS.SaveDefaultSettings() > *** Now go get any previous settings that were saved > THIS.RestoreGridSettings() >ENDIF >>
>*-- Save the grid properties when it is instantiated >LOCAL lnCol >WITH THIS > DIMENSION .aprops[ .ColumnCount, 3 ] > FOR lnCol = 1 TO .COLUMNCOUNT > .aprops[ lnCol, 1 ] = .COLUMNS[ lnCol ].NAME > .aprops[ lnCol, 2 ] = .COLUMNS[ lnCol ].COLUMNORDER > .aprops[ lnCol, 3 ] = .COLUMNS[ lnCol ].WIDTH > ENDFOR >ENDWITH >>
> *-- Configure the grid using the information saved in the Grd_Prefrence table > LOCAL lcSQL, loCol, lnHandle > lcSQL = [SELECT column_name, column_order, column_width FROM grid_preference WHERE path_name = '] > lcSQL = lcSQL + SYS( 1272, THIS ) + [' AND user_id = ] + ; > IIF( VARTYPE( oApp ) = [O], TRANSFORM( oApp.sys_user_id ), [-1] ) + [ INTO CURSOR qTmp] > &lcSQL > > *** See if we got comething - if we didn't, this is the first time > *** that this form has been run - we have no preferences to restore > IF RECCOUNT( [qTmp] ) > 0 > FOR EACH loCol IN THIS.COLUMNS > SELECT qTmp > LOCATE FOR column_name = loCol.NAME > IF FOUND() > loCol.COLUMNORDER = qTmp.column_order > loCol.WIDTH = qTmp.column_width > ENDIF > ENDFOR > ELSE > THIS.lpreferencesexist = .F. > ENDIF >>
> *-- Called when the grid is destroyed to write the current configuration to the grid preference table > PROCEDURE savegridsettings > LOCAL lcSQL, loCol, lnHandle > IF THIS.COLUMNCOUNT > 0 > *** if we do not yet have preferences saved for this grid and this user > *** we need to insert a record, otherwise, we update > FOR EACH loCol IN THIS.COLUMNS > IF THIS.lpreferencesexist > lcSQL = [UPDATE grid_preference SET column_order = ] + TRANSFORM( loCol.COLUMNORDER ) > lcSQL = lcSQL + [, column_width = ] + TRANSFORM( loCol.WIDTH ) > lcSQL = lcSQL + [ WHERE path_name = '] + SYS( 1272, THIS ) + [' AND column_name = '] > lcSQL = lcSQL + loCol.NAME + [' AND user_id = ] + IIF( VARTYPE( oApp ) = [O], TRANSFORM( oApp.sys_user_id ), [-1] ) > ELSE > lcSQL = [INSERT INTO grid_preference ( user_id, path_name, column_name, column_order, column_width ) VALUES (] > lcSQL = lcSQL + IIF( VARTYPE( oApp ) = [O], TRANSFORM( oApp.sys_user_id ), [-1] ) + [, '] > lcSQL = lcSQL + SYS( 1272, THIS ) + [', '] + loCol.NAME + [', ] + TRANSFORM( loCol.COLUMNORDER ) + [, ] + TRANSFORM( loCol.WIDTH ) + [ )] > ENDIF > &lcSQL > ENDFOR > ENDIF > ENDPROC > > > *-- Called from the right-click of the grid to restore the grid configuration to its default > PROCEDURE showmenu > LOCAL lnChoice > > *** If we do not have any columns, do nothing > IF THIS.COLUMNCOUNT > 0 > *** Define the pop-up menu for resetting the grid to the default > STORE 0 TO lnChoice > DEFINE POPUP Reset2Default SHORTCUT RELATIVE FROM MROW(),MCOL() > DEFINE BAR 1 OF Reset2Default PROMPT "Reset Grid Columns" > ON SELECTION BAR 1 OF Reset2Default lnChoice = 1 > > *** Activate the menu and process the result > ACTIVATE POPUP Reset2Default > IF lnChoice = 1 > *** We want to delete the preferences and reinitialize the grid > THIS.RESETTODEFAULT() > ENDIF > ENDIF > ENDPROC > > PROCEDURE DESTROY > THIS.savegridsettings() > ENDPROC > > > PROCEDURE RESETTODEFAULT > LPARAMETERS cProperty > *********************************************************************** > *** Changed By.: Marcia G. Akins on 27 August 2005 > *** Reason.....: Shanghai the native method to reset the grid columns > *** ...........: to what they were when the form was instantiated > *********************************************************************** > LOCAL lnCol > WITH THIS > FOR lnCol = 1 TO .COLUMNCOUNT > .COLUMNS[ lnCol ].COLUMNORDER = .aprops[ lnCol, 2 ] > .COLUMNS[ lnCol ].WIDTH = .aprops[ lnCol, 3 ] > ENDFOR > ENDWITH > NODEFAULT > ENDPROC > > > PROCEDURE RIGHTCLICK > THIS.showmenu() > ENDPROC >