我可以在数据窗口里的Doubleclicked里写双击这列进行排序,但如何双击这列的标头来进行排序?
IF DWO.Name="code" THEN
string newsort
newsort = "code ds"
dw_1.SetSort(newsort)
dw_1.Sort( )
end if
------解决方案--------------------
---供你参考吧
string ls_CurObj, ls_CurCol
integer li_LinePos
ls_CurObj = String(dwo.Name) //获取点击对象的名称
//获取点击对象右侧20大小的坐标
li_LinePos = Integer(This.Describe(ls_CurObj + ".X"))&
+ (Integer(This.Describe(ls_CurObj + ".Width")) - 20)
If Row = 0 AND This.Describe(ls_CurObj + ".Text") <> "!" AND&
This.Describe(ls_CurObj + ".Band") = "header" Then //点击的是Header
ls_CurCol = Left(ls_CurObj,Len(ls_CurObj) - 2) //获取列名
If is_OrderCol <> ls_CurCol Then //没有进行过排序
is_OrderCol = Left(ls_CurObj,Len(ls_CurObj) - 2) //保存上次排序列
//of_asc(li_linePos) //升序排序
is_SortType = "A" //记录上次排序顺序
This.SetSort(is_OrderCol + " " + is_SortType) //设置排序规则
This.Sort() //排序
Else //进行过排序
If is_SortType = "A" Then //如果是升序
li_LinePos -= 20 //调整图标位置
//of_des(li_LinePos) //则降序排序
is_SortType = "D" //记录上次排序规则
Else //如果是降序
//of_asc(li_LinePos) //则升序排序
is_SortType = "A" //记录上次排序规则
End If
This.SetSort(is_OrderCol + " " + is_SortType)
This.Sort()
End If
End If
------解决方案--------------------
//定义一个函数pub_f_datastore,用于判断升降序标志
//string pub_f_datasort(datawindow dataname,integer pos_x,integer flag)
long pos_temp
long t_pos
string ls
string t_col_name
string sort_list
ls = dataname.describe("datawindow.objects")
do while ((pos(ls,"~t") > 0) or (trim(ls) <> ""))
t_pos = pos(ls,"~t") - 1
if t_pos < 1 then
t_pos = len(trim(ls))
end if
t_col_name = mid(ls,1,t_pos)
if ((upper(dataname.describe(t_col_name + ".type")) = "COLUMN") or (upper(dataname.describe(t_col_name + ".type")) = "COMPUTE")) and upper(string(dataname.describe(t_col_name + ".Band"))) = "DETAIL" then
pos_temp = long(dataname.describe(t_col_name + ".X"))
if pos_x = pos_temp then
if flag = 1 then
sort_list = t_col_name + " A"
end if
if flag = 0 then
sort_list = t_col_name + " D"
end if
dataname.setsort(sort_list)
dataname.sort()
return t_col_name
end if
end if
ls = mid(ls,t_pos + len("~t") + 1)
loop
return ""
//在数据窗口内定义一个实例变量is_pre_sort_name,用于存储上次排序的列
//定义函数uf_dwsort(dwobject dwo,long row),代码如下
string ls_colname
string ls_flag
long ll_arrowcolor = 16711935
string ls
if isnull(dwo) then
return -1
end if
if rowcount() = 0 then
return -1
end if
if pos(string(dwo.type),"compute") = 0 and pos(string(dwo.type),"text") = 0 then
return -1
end if
if pos(string(dwo.band),"header") = 0 then
return -1
end if
choose case upper(string(dwo.name))
case "easy_NO_T", "SPACE_NAME_T", "DATAWINDOW"//有些栏目不需要排序的,比如序号列等;
return -1
case else
end choose
if is_pre_sort_name = "A" then
ls_colname = myWork.pub_f_datasort(this,long(string(dwo.x)),0)
ls_flag = "_d"
is_pre_sort_name = "D"
modify("destroy easy_sort_a")
else
ls_colname = myWork.pub_f_datasort(this,long(string(dwo.x)),1)
is_pre_sort_name = "A"