* Grid.RefreshAfterSorting * Used grid custom properties: * lSorting - flag that indicates sorting refreshing, so all activity related with row * change in grid should be disabled for the duration of this routine * nRecno - stores record number of current row in grid. This property should be populated * in the AfterRowColChange event by record number each time record number changed * lInit - flag, should be .T. when Init method is running lparameters poColumn * column reference should be passed of column being sorted * called internally only as event from the column header after sorting with this .lSorting = .T. && above flag used in the AfterRowColChange and other grid events to do not fire && any code during running of this method. This method might cause weird record && moving by grid when sorted, so anyway it is required. We will force record && moveng too for better refreshing. local lcOldArea, lcGridAlias m.lcOldArea = select(0) m.lcGridAlias = this.RecordSource select (m.lcGridAlias) * store 'real' grid position, this is needed because it might change in the * next chapter local nOldRecNo m.nOldRecNo = .nRecno && nRecNo - property that updated in AfterRowColChange event && of grid in AfterRowColChange event flag lSorting prevents && change of this property && restore row position - it might be changed during indexing and cell activation && after refresh after sorting you can see grid shows, for example, last row only, && when really it contains 3 rows and all fit into grid. This is a problem we going && to solve by following code lines * this must be BEFORE any refresh of grid if between(m.nOldRecNo,1,reccount()) LOCATE && FOR .T., same as 'go top', but works more quickly for && filtered data ENDIF .Refresh() && activate cell that is appropriate to sorting column, && so grid will not scroll out from sorting column. When we do not do this, after && click on the header, grid will scroll to current cell (column) focused, that && might hide (scroll out) column that is just sorted - looks confusing. if !.lInit && flag that is .T. when Init method is running. m.poColumn.SetFocus() if between(m.nOldRecNo,1,reccount()) go (m.nOldRecNo) ENDIF else && during Grid Init, however, we should not do this because SetFocus will && cause error. Just refresh it. This is needed to check for case when we && want to restore grid sorting when form loads from user preferenses if between(m.nOldRecNo,1,reccount()) go (m.nOldRecNo) ENDIF .Refresh() endif select (m.lcOldArea) DOEVENTS && this is required before any other actions to correctly refresh grid && and do not move record pointer weirdly .lSorting = .F. endwith