local lcOrder, lnPos lnPos=rat('.',this.parent.controlsource) lcOrder=substr(this.parent.ControlSource,lnPos+1) if tagno(lcOrder)>0 && This index already exists (assume simple indexes tagname=fieldname) set order to (lcOrder) else * You may want to index on this field now - a little dangerous index on &lcOrder tag (lcOrder) endifIn our classlib we have a grid, which has a method SetOrder.
LPARAMETERS tcControlSource LOCAL lnCount, lcField *-- Sets the order to the currently selected *-- controlsource if possible *-- Get the fieldname being used lcField = ; SUBSTR(tcControlSource, AT(".", tcControlSource) + 1) *-- See if the field name is in the leftmost part of the index *-- expression. If so, SET ORDER TO the index. FOR lnCount = 1 TO TAGCOUNT() IF UPPER(SYS(14, lnCount)) = UPPER(lcField) SET ORDER TO lnCount IF TYPE("thisform") == "O" thisform.Refresh() ENDIF EXIT ENDIF ENDFOR