Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Moving couple columns in a grid
Message
From
18/12/2000 07:34:29
 
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00427567
Message ID:
00454623
Views:
17
>Hi!
>
>>Now the second question:
>>How can I make my grid to save user's settings? IOW, in run-time I adjust columns width and columns order for the particular grid (this grid is made as a class, if it does matter). Next time I invoke my form, I want these settings to be in effect.
>
> Looks like you gonna to recreate all functionality of our grid ;) <g>
>
> See code below. I just cut and copy with corrections, but it still requires some work on it (I'm not sure it is correct because a lot of changes needed to remove all our framework-specific things). I put it as general idea only. You may also use other tools to save/restore values, like registry or user profile table on the server.
>
>

>
>*-- DECLARE DLL statements for reading/writing to private INI files
>DECLARE INTEGER GetPrivateProfileString IN Win32API AS GetPrivStr ;
> String cSection, String cKey, String cDefault, String @cBuffer, ;
> Integer nBufferSize, String cINIFile
>
>DECLARE INTEGER WritePrivateProfileString IN Win32API AS WritePrivStr ;
> String cSection, String cKey, String cValue, String cINIFile
>
>
>procedure SaveGridLayout
>* parameter - grid ID in profile. If not specified, form name and grid name will be used
>* Note also that it is good style to include form name at the start of the grid layout saving signature.
>lparameters pcGridID
>
>local lcGridId, lnCounter, lcValue, lcNameID, loHeader, lnSortingState, tnX
>if vartype(m.pcGridID) == "C" and !empty(m.pcGridID)
> m.lcGridId = upper(allt(m.pcGridID))
>else
> m.lcGridId = upper(thisform.Name + '_' + this.Name)
>endif
>
>with this
>* save grid layout into user profile:
>* 1. Save current record position
> m.lcNameID = m.lcGridId + "_position"
> m.lcValue = allt(STR(RECNO(.GetGridAlias()),12,0))
> =WritePrivStr("Grids", m.lcNameId , ;
> m.lcValue, CURDIR() + INIFILE)
>
>* 2. Save header and row height
> m.lcNameID = m.lcGridId + "_HRHeight"
> m.lcValue = allt(STR(.HeaderHeight,10,0)) + ',' + allt(STR(.RowHeight,10,0))
> =WritePrivStr("Grids", m.lcNameId , ;
> m.lcValue, CURDIR() + INIFILE)
>
>* 3. Save columns layout
> FOR m.lnCounter = 1 TO .COLUMNCOUNT
> m.loHeader = .GetColumnHeader(.COLUMNS(m.lnCounter))
> with .COLUMNS(m.lnCounter)
> if !empty(.CONTROLSOURCE)
> m.lcValue = .Width
> if vartype(m.loHeader) == "O"
> && save sorting if any
> if PEMSTATUS(m.loHeader,'state',5)
> m.lnSortingState = m.loHeader.state
> else
> m.lnSortingState = 0
> endif
> else
> m.lnSortingState = 0
> endif
> m.lcValue = ALLTR(STR(m.lcValue, 10, 0)) + ',' + ;
> ALLTR(STR(.COLUMNORDER,10,0))
>
> * Save sorting order for sorted column
> if this.nSortColumn = m.lnCounter AND m.lnSortingState > 0
> m.lcValue = m.lcValue + ',' + allt(str(m.lnSortingState,2,0))
> endif
>
> m.lcNameId = m.lcGridId + "_" + iif('.' $ .CONTROLSOURCE, ;
> SUBSTR(.CONTROLSOURCE,AT(".",.CONTROLSOURCE) + 1), ;
> .CONTROLSOURCE)
>
> =WritePrivStr("Grids", m.lcNameId , ;
> m.lcValue, CURDIR() + INIFILE)
> endif
> endwith
> ENDFOR
>endwith
>endproc
>
>***************************************************************
>procedure RestoreGridLayout
>* parameter - grid ID in profile. If not specified, form name and grid name will be used
>* Note also that it is good style to include form name at the start of the grid layout saving signature.
>
>* Second parameter - set it to .T. in case when you need to restore layout only without change of record number (used in shortcut menu item 'restore original layout')
>
>lparameters pcGridID, llDoNotRestoreRecord
>
>local lcGridId, lnCounter, lcBuffer, lcValue, lcNameID, loHeader, lnSortingState, lcAlias, tnX, lnPos
>if vartype(m.pcGridID) == "C" and !empty(m.pcGridID)
> m.lcGridId = upper(allt(m.pcGridID))
>else
> m.lcGridId = upper(thisform.Name + '_' + this.Name)
>endif
>
>with this
> .nSortColumn = 0 && clear it for future use
> m.lcAlias = .GetGridAlias()
>
> * 1. Restore header and row height
> m.lcNameID = m.lcGridId + "_HRHeight"
> m.lcBuffer = SPACE(100) + CHR(0)
> IF GetPrivStr("Grids", m.lcNameId, "", ;
> @m.lcBuffer, 100, ;
> CURDIR() + INIFILE) > 0
> m.lcValue = val(alltr(m.lcBuffer))
> if m.lcValue >= 0
> .HeaderHeight = m.lcValue
> .OldHeaderHeight = .HeaderHeight
> endif
> m.lnPos = at(',',alltr(m.lcBuffer))
> if m.lnPos > 0
> m.lcValue = val( substr(alltr(m.lcBuffer), m.lnPos + 1) )
> if m.lcValue > 0
> .RowHeight = m.lcValue
> .OldRowHeight = .RowHeight
> endif
> endif
> ENDIF
>
> * 2. Restore columns layout
> m.lnSortingState = 0
> local loHeader
> FOR m.lnCounter = 1 TO .COLUMNCOUNT
> with .COLUMNS(m.lnCounter)
> if !empty(.CONTROLSOURCE)
> m.lcBuffer = SPACE(100) + CHR(0)
> m.lcNameId = m.lcGridId + "_" + iif('.' $ .CONTROLSOURCE, ;
> SUBSTR(.CONTROLSOURCE,AT(".",.CONTROLSOURCE) + 1), ;
> .CONTROLSOURCE)
>
> IF GetPrivStr("Grids", m.lcNameId, "", ;
> @lcBuffer, 100, ;
> CURDIR() + INIFILE) > 0
> m.lcValue = val(alltr(m.lcBuffer))
> if m.lcValue > 0
> .WIDTH = m.lcValue
> endif
> m.lnPos = at(',',alltr(m.lcBuffer),1)
> if m.lnPos > 0
> m.lcValue = val( substr(alltr(m.lcBuffer), m.lnPos + 1) )
> if m.lcValue > 0
> .COLUMNORDER = m.lcValue
> endif
> m.lnPos = at(',',alltr(m.lcBuffer),2)
> if m.lnPos > 0
> m.lcValue = val( substr(alltr(m.lcBuffer), m.lnPos + 1) )
> if m.lcValue > 0
> this.nSortColumn = m.lnCounter
> m.lnSortingState = m.lcValue
> endif
> endif
> endif
> ENDIF && GetPrivStr... > 0
> endif && !empty(.ControlSource)
> endwith
> ENDFOR
> m.loHeader = ""
>
> * 3. Sort column if sorting stored
> if .nSortColumn > 0 AND m.lnSortingState > 0
> .SortColumn(.nSortColumn, m.lnSortingState)
> endif
>
> * 4. Restore current record position
> if !m.llDoNotRestoreRecord
> if used(m.lcAlias)
> m.lcNameID = m.lcGridId + "_position"
> m.lcBuffer = SPACE(100) + CHR(0)
> IF GetPrivStr("Grids", m.lcNameId, "", ;
> @m.lcBuffer, 100, ;
> CURDIR() + INIFILE) > 0
> m.lcValue = val(alltr(m.lcBuffer))
> if between(m.lcValue, 1, reccount(m.lcAlias))
> go (m.lcValue) in (m.lcAlias)
> endif
> .nRecno = recno(m.lcAlias)
> .Refresh()
> ELSE
> GO TOP in (m.lcAlias)
> .Refresh()
> ENDIF
> endif
> endif
>
> .RefreshHeaders()
> .RefreshIndicator()
>endwith
>endproc
>

Hi Vlad,
I cant found the GetGridAlias() function.
Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform