我的原话是:“在 THISFORM.Refresh 之后添加一行:THIS.Parent.SetFocus”,修改后的完整代码如下:
DEFINE CLASS MyHeader as Header
name = 'Header1'
PROCEDURE Click
LOCAL nSelect,cFldName,cAlias,nNum_Tag
cAlias = JUSTFNAME(THIS.Parent.ControlSource)
&& 表名
cFldName = JUSTEXT(THIS.Parent.ControlSource)
&& 字段名
cOldPict = JUSTSTEM(THIS.Picture)
&& 当前图片
THIS.Parent.Parent.SetAll('Picture','')
&& 先去除所有图片
nSelect = SELECT()
SELECT (cAlias)
nNum_Tag = ATAGINFO(aTag)
DO CASE
CASE ATC('up',cOldPict) > 0
&& 升序时降序
THIS.Picture = 'dowm.bmp'
IF nNum_Tag > 0 AND ASCAN(aTag,cFldName,-1,-1,1,7) > 0 && 若索引标记存在,则激活之
SET ORDER TO &cFldName DESCENDING
ELSE
INDEX ON &cFldName TAG (cFldName) DESCENDING
&& 索引标记不存在,新建之
ENDIF
CASE ATC('down',cOldPict) > 0
&& 降序时无序
SET ORDER TO
OTHERWISE
&& 无序时升序
THIS.Picture = 'up.bmp'
IF nNum_Tag > 0 AND ASCAN(aTag,cFldName,-1,-1,1,7) > 0
SET ORDER TO &cFldName
ELSE
INDEX ON &cFldName TAG (cFldName)
ENDIF
ENDCASE
lFlag = .f.
SCAN
REPLACE flag WITH lFlag
lFlag = !lFlag
ENDSCAN
GO TOP
THISFORM.Refresh
THIS.Parent.SetFocus
SELECT (nSelect)
ENDPROC
ENDDEFINE
行记录不是“跳来跳去”,每次单击列标题后跳转到“第一条”记录,这也是大多数人的需要。如果你想单击列标题后保留原记录,也很简单,代码稍作修改如下:
DEFINE CLASS MyHeader as Header
name = 'Header1'
PROCEDURE Click
LOCAL nSelect,cFldName,cAlias,nNum_Tag
cAlias = JUSTFNAME(THIS.Parent.ControlSource)
&& 表名
cFldName = JUSTEXT(THIS.Parent.ControlSource)
&& 字段名
cOldPict = JUSTSTEM(THIS.Picture)
&& 当前图片
THIS.Parent.Parent.SetAll('Picture','')
&& 先去除所有图片
nSelect = SELECT()
SELECT (cAlias)
nRec = IIF(EOF(),0,RECNO())
nNum_Tag = ATAGINFO(aTag)
DO CASE
CASE ATC('up',cOldPict) > 0
&& 升序时降序
THIS.Picture = 'dowm.bmp'
IF nNum_Tag > 0 AND ASCAN(aTag,cFldName,-1,-1,1,7) > 0 && 若索引标记存在,则激活之
SET ORDER TO &cFldName DESCENDING
ELSE
INDEX ON &cFldName TAG (cFldName) DESCENDING
&& 索引标记不存在,新建之
ENDIF
CASE ATC('down',cOldPict) > 0
&& 降序时无序
SET ORDER TO
OTHERWISE
&& 无序时升序
THIS.Picture = 'up.bmp'
IF nNum_Tag > 0 AND ASCAN(aTag,cFldName,-1,-1,1,7) > 0
SET ORDER TO &cFldName
ELSE
INDEX ON &cFldName TAG (cFldName)
ENDIF
ENDCASE
lFlag = .f.
SCAN
REPLACE flag WITH lFlag
lFlag = !lFlag
ENDSCAN
*
GO TOP
IF nRec # 0
GO nRec
ENDIF
THISFORM.Refresh
THIS.Parent.SetFocus
SELECT (nSelect)
ENDPROC
ENDDEFINE
“师父领进门,修行在个人”。如果自己没有独立思考能力,单靠他人指导是不行的。