是想通过这个判断,来改变排序方式。
如果是升序,再点击排序时就按降序。
是不是要声明一个变量来进行判断?
4 个解决方案
#1
你是怎么排序的?INDEX ON、SORT ON?
#2
如果是INDEX,则
? DESCENDING()
升序为FALSE
? DESCENDING()
升序为FALSE
#3
请参考
如何实现点击Grid控件的列标头,然后数据按此列进行升序或降序排序?
*---------------------------------------
如:表有如下字段:
姓名 数学 语文 英语
如何实现点哪一列,数据表就按哪列升序或降序排列
如何实现点击Grid控件的列标头,然后数据按此列进行升序或降序排序?
*---------------------------------------
如:表有如下字段:
姓名 数学 语文 英语
如何实现点哪一列,数据表就按哪列升序或降序排列
方法一:
*在表单中加入一新方法,取名为MSORT
*(新建的方法或属性将出现在属性窗口的最底部)。
*然后在此方法中写入以下代码:
Lparameters xfield,xsort,xcol,xGrid,xtable &&**..字段名,升降序,第几列,表格名,表名
If Parameters()<5
Return .F.
Endif
Set Index To
Local TEM1
If xsort='△'
Select * From &xtable Order By &xfield Desc Into Cursor TEM1
Else
Select * From &xtable Order By &xfield Asc Into Cursor TEM1
Endif
If _Tally>0
Select (xtable)
Zap
Append From Dbf('TEM1')
Else
Return
Endif
vst='ThisForm.'+xGrid
If !Empty(vst)
For i=1 To &vst..ColumnCount &&**..先去掉▽(△)再加△(▽)
st0=vst+'.Column'+Alltrim(Str(i))+'.Header1.Caption'
If At(Right(Allt(&st0),2),"▽△")!=0
&st0.=Left(Alltrim(&st0),Len(Alltrim(&st0))-2)
Endif
If i=xcol &&**..第几例
If At(xsort,"▽△")=0.Or.xsort="▽"
&st0.=&st0+"△"
Else
&st0.=&st0+"▽"
Endif
Endif
Endfor
Endif
Select (xtable)
Thisform.Refresh
Select (xtable)
Go Top
Thisform.Refresh
*然后把Grid控件的ColumnCount修改为你的列数,在Grid的每列的Header1的CLICK(单击)或者其它(如双击)中写入﹕
Thisform.Msort(This.Parent.ControlSource,Right(Allt(This.Caption),2),Val(Substr(This.Parent.Name,7,2)),This.Parent.Parent.Name,This.Parent.Parent.RecordSource) &&**..字段名,升降序,第几列,表名,表名
---------------------------------------------------------------
方法二:
*例如:前三列分别是f1,f2,f3
*把Grid控件的ColumnCount修改为3或你的列数
*表单的LOAD事件:
Public nF1,nF2,nF3
nF1=0
nF2=0
nF3=0
Use tmp
Index On f1 Tag f1 Of FFHSY &&创建非结构复合索引(提高速度)
Index On f2 Tag f2 Of FFHSY &&创建非结构复合索引(提高速度)
Index On f3 Tag f3 Of FFHSY &&创建非结构复合索引(提高速度)
Set Order To
Go Top
*Grid第一列标头的CLICK事件:
If nF1=0
Set Order To F1 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF1=1
Else
Set Order To F1 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF1=0
Endif
For I=2 To 3
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endfor
Go Top
Thisform.Grid1.Refresh
*Grid第二列标头的CLICK事件:
If nF2=0
Set Order To F2 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF2=1
Else
Set Order To F2 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF2=0
Endif
For I=1 To 3
If I!=2
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endif
Endfor
Go Top
Thisform.Grid1.Refresh
*Grid第三列标头的CLICK事件:
If nF3=0
Set Order To F3 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF3=1
Else
Set Order To F3 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF3=0
Endif
For I=1 To 2
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endfor
Go Top
Thisform.Grid1.Refresh
*你还可以设置一个按钮用于取消排序:
Set Orde To
Go Top
Thisform.Grid1.Refresh
#4
厉害!不愧为版主!
#1
你是怎么排序的?INDEX ON、SORT ON?
#2
如果是INDEX,则
? DESCENDING()
升序为FALSE
? DESCENDING()
升序为FALSE
#3
请参考
如何实现点击Grid控件的列标头,然后数据按此列进行升序或降序排序?
*---------------------------------------
如:表有如下字段:
姓名 数学 语文 英语
如何实现点哪一列,数据表就按哪列升序或降序排列
如何实现点击Grid控件的列标头,然后数据按此列进行升序或降序排序?
*---------------------------------------
如:表有如下字段:
姓名 数学 语文 英语
如何实现点哪一列,数据表就按哪列升序或降序排列
方法一:
*在表单中加入一新方法,取名为MSORT
*(新建的方法或属性将出现在属性窗口的最底部)。
*然后在此方法中写入以下代码:
Lparameters xfield,xsort,xcol,xGrid,xtable &&**..字段名,升降序,第几列,表格名,表名
If Parameters()<5
Return .F.
Endif
Set Index To
Local TEM1
If xsort='△'
Select * From &xtable Order By &xfield Desc Into Cursor TEM1
Else
Select * From &xtable Order By &xfield Asc Into Cursor TEM1
Endif
If _Tally>0
Select (xtable)
Zap
Append From Dbf('TEM1')
Else
Return
Endif
vst='ThisForm.'+xGrid
If !Empty(vst)
For i=1 To &vst..ColumnCount &&**..先去掉▽(△)再加△(▽)
st0=vst+'.Column'+Alltrim(Str(i))+'.Header1.Caption'
If At(Right(Allt(&st0),2),"▽△")!=0
&st0.=Left(Alltrim(&st0),Len(Alltrim(&st0))-2)
Endif
If i=xcol &&**..第几例
If At(xsort,"▽△")=0.Or.xsort="▽"
&st0.=&st0+"△"
Else
&st0.=&st0+"▽"
Endif
Endif
Endfor
Endif
Select (xtable)
Thisform.Refresh
Select (xtable)
Go Top
Thisform.Refresh
*然后把Grid控件的ColumnCount修改为你的列数,在Grid的每列的Header1的CLICK(单击)或者其它(如双击)中写入﹕
Thisform.Msort(This.Parent.ControlSource,Right(Allt(This.Caption),2),Val(Substr(This.Parent.Name,7,2)),This.Parent.Parent.Name,This.Parent.Parent.RecordSource) &&**..字段名,升降序,第几列,表名,表名
---------------------------------------------------------------
方法二:
*例如:前三列分别是f1,f2,f3
*把Grid控件的ColumnCount修改为3或你的列数
*表单的LOAD事件:
Public nF1,nF2,nF3
nF1=0
nF2=0
nF3=0
Use tmp
Index On f1 Tag f1 Of FFHSY &&创建非结构复合索引(提高速度)
Index On f2 Tag f2 Of FFHSY &&创建非结构复合索引(提高速度)
Index On f3 Tag f3 Of FFHSY &&创建非结构复合索引(提高速度)
Set Order To
Go Top
*Grid第一列标头的CLICK事件:
If nF1=0
Set Order To F1 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF1=1
Else
Set Order To F1 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF1=0
Endif
For I=2 To 3
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endfor
Go Top
Thisform.Grid1.Refresh
*Grid第二列标头的CLICK事件:
If nF2=0
Set Order To F2 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF2=1
Else
Set Order To F2 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF2=0
Endif
For I=1 To 3
If I!=2
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endif
Endfor
Go Top
Thisform.Grid1.Refresh
*Grid第三列标头的CLICK事件:
If nF3=0
Set Order To F3 Ascending &&升序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↑'
nF3=1
Else
Set Order To F3 Descending &&降序
This.Caption=Strtran(Strtran(This.Caption,'↑',''),'↓','')+'↓'
nF3=0
Endif
For I=1 To 2
Thisform.Grid1.Columns(I).Header1.Caption=Strtran(Strtran(Thisform.Grid1.Columns(I).Header1.Caption,'↑',''),'↓','')
Endfor
Go Top
Thisform.Grid1.Refresh
*你还可以设置一个按钮用于取消排序:
Set Orde To
Go Top
Thisform.Grid1.Refresh
#4
厉害!不愧为版主!