Bertiethedog
Programmer
I have been writing a form that opens any table and presents it in a grid.
I have the facility to sort the grid by clicking on the header of that column.
At the mo the table I am experimenting with has 7 fields. If I click on Field 3 then then it resort fine but the method that I use to reset the headers (header name & width) will not work on the column that has just been sorted
The resort code is here
This bit of code was placed on here and I lifted it, it is not my own work
The customer wants the prog to remember the row & order so that is what is stored in the table
The select code is dead simple
so just one problem but has anyone got any ideas
Richard
I have the facility to sort the grid by clicking on the header of that column.
At the mo the table I am experimenting with has 7 fields. If I click on Field 3 then then it resort fine but the method that I use to reset the headers (header name & width) will not work on the column that has just been sorted
The resort code is here
Code:
private laEvents[ 1 ], loHeader, lcField, loColumn, lcFrom, lnBuffering, lcSortOrder, loControl
private llFoundColumn, llAllowCellSelection
*** First of all, see which column fired off this event
Aevents( laEvents, 0 )
loHeader = laEvents[ 1 ]
If Vartype( loHeader ) = 'O'
*** First See if a ControlsSource was set for the column
With loHeader.Parent
lcField = ''
If Not Empty( .ControlSource )
*** Cool. Use it to decide how to sort the grid
If Not Empty( .ControlSource ) And ( '.' $ .ControlSource ) And Not( '(' $ .ControlSource )
lcField = Justext( .ControlSource )
WAIT WINDOW lcField
Endif
Endif
ENDWITH
*** if we have a field - let's sort
RETURN lcField
ENDIF
RETURN
*-* This bit is not used
*** we have a field - let's see if it already has a sort order set
*** if it does, it will have the appropriate picture in the header
lcSortOrder = ''
If Not Empty( loHeader.Picture )
lcSortOrder = Iif( Lower( Justfname( loHeader.Picture ) ) == 'down.bmp', '', 'DESC' )
Else
*** See if there is a visual cue on any of the other grid
*** column headers and remove it if there is
*-*FOR EACH loColumn IN This.Columns
For Each loColumn In Thisform.grid2.Columns
For Each loControl In loColumn.Controls
If Lower( loControl.BaseClass ) == [header]
If Not Empty( loControl.Picture )
llFoundColumn = .T.
loControl.Picture = []
loControl.FontBold = .F.
Exit
Endif
Endif
Endfor
If llFoundColumn
Exit
Endif
Endfor
Endif
This bit of code was placed on here and I lifted it, it is not my own work
The customer wants the prog to remember the row & order so that is what is stored in the table
The select code is dead simple
Code:
lcTable = ALLTRIM(menuoptions.table)
lcOrder = thisform.getOrder()
PRIVATE lcStr, ;
lcField, ;
lnVar, ;
lnPos
IF !USED('GenTable')
USE (lcTable) IN 0 ALIAS Gentable
ENDIF
IF USED('dispdata')
USE IN dispdata
endif
SELECT GenTable
lcStr = 'RECNO() AS "Record"'
FOR i = 1 TO FCOUNT()
lcField = RTRIM(FIELD(i))
COUNT FOR !EMPTY(&lcField) TO lnVar
IF lnVar > 0
lcStr = (lcfield) + ',' + lcStr
ENDIF
NEXT
lcResultFile = SYS(2023) + '\dispdata'
SELECT &lcStr ;
FROM GenTable ;
ORDER BY &lcOrder ;
INTO CURSOR dispdata
*-*TABLE (lcResultFile)
lnArea = ALIAS()
lnPos = thisform.GetPos()
SELECT (lnArea)
*-* trap the fact that some records might have been deleted
lnPos = IIF(lnPos <= RECCOUNT(), lnPos,RECCOUNT())
GOTO lnPos
so just one problem but has anyone got any ideas
Richard