高手请帮忙呀,数据窗口的排序问题

Devlinzy 2003-09-04 10:30:49
想实现当点击数据窗口的标题时
数据窗口中的数据按照,所点击的标题的条件进行排序
如下:
no name sex
1 a g
2 c b
3 b b
点击no,记录的顺序首尾倒置(逆序),再点击一次变成原来的顺序(正序)
其他的列也是同样,数据记录是通过很多的限制条件查询得到的
这样的功能很普通,大家都见过
新手,还请大家赐教,最好写的详细点


...全文
34 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
runsoft 2003-09-08
  • 打赏
  • 举报
回复
不晚,
119119 2003-09-08
  • 打赏
  • 举报
回复
来晚了已经。
klbt 2003-09-05
  • 打赏
  • 举报
回复
在数据窗口的Clicked事件编码:

String Column, Text

if dwo.Type = 'text' then
Text = dwo.Name
Column = Left(Text, Len(Text) - 2)
if is_sort = " A" then
is_sort = " D"
else
is_sort = " A"
end if
this.SetSort(Column + is_sort)
this.Sort()
end if
incats 2003-09-05
  • 打赏
  • 举报
回复
前提是你的列标题名没有更改过, 就是默认为XXXX_t, 否则还得弄个函数, 获取列标题所对应的列名.
qiyousyc 2003-09-05
  • 打赏
  • 举报
回复
回答得这么仔细!
ltsiphon 2003-09-05
  • 打赏
  • 举报
回复
对了,Text应该为instance Variables.
sorry.
ltsiphon 2003-09-05
  • 打赏
  • 举报
回复
白兔兄的方法简单,明了。
而且,再加一个判断,也许会使这个功能更加实用。

String Column, Text

if dwo.Type = 'text' then
if Text = dwo.Name then
Column = Left(Text, Len(Text) - 2)
if is_sort = " A" then
is_sort = " D"
else
is_sort = " A"
end if
else
Text = dwo.Name
Column = Left(Text, Len(Text) - 2)
is_sort = " A"
end if
this.SetSort(Column + is_sort)
this.Sort()
end if
这样,可以避免连续的两次针对不同列的点击造成的排序没有按照我们的意思执行的状态。
eastpond 2003-09-05
  • 打赏
  • 举报
回复
白兔兄的简洁明了
jdsnhan(柳荫凉)有图示,效果会更好
workhand 2003-09-05
  • 打赏
  • 举报
回复

String Column, Text

if dwo.Type = 'text' then
Text = dwo.Name
Column = Left(Text, Len(Text) - 2)
if is_sort = " A" then
is_sort = " D"
else
is_sort = " A"
end if
this.SetSort(Column + is_sort)
this.Sort()
end if
白兔兄的最明了,最好了。
jdsnhan 2003-09-05
  • 打赏
  • 举报
回复
在数据窗口的Clicked事件编码
string str_objectname,str_curcol,str_addpic
integer int_pic_x

str_objectname=string(dwo.name) //对象名称
if row=0 and this.describe(str_objectname+".band")="header" and this.describe(str_objectname+".text")<>"!" then //是否点击列对象
str_curcol=left(str_objectname,len(str_objectname) - 2) //当前列对象名称
if str_curcol<>i_str_oldcol then //点击的是不同列对象
this.modify("destroy p_sort") //不管有没有位图对象都删除
i_str_oldcol=str_curcol //保存上次点击的列对象
//画图
int_pic_x=integer(this.describe(str_objectname+".x"))+(integer(this.describe(str_objectname+".width")) - 70)
str_addpic='create bitmap(band=foreground filename="up.bmp" x="'+string(int_pic_x)+'" y="24" height="33" width="51" border="0" name=p_sort visible="1")'
this.modify(str_addpic) //动态画个图
this.setsort(str_curcol +" A") //头一次点击当然是升序了
this.sort()
else //当前列已经点过了
if this.describe("p_sort.filename")="up.bmp" then //上次是升序
this.modify("p_sort.filename='down.bmp'")
this.setsort(str_curcol+" D") //这次是降序
else
this.modify("p_sort.filename='up.bmp'")
this.setsort(str_curcol+" A")
end if
this.sort()
end if
end if
liujiaqiang 2003-09-04
  • 打赏
  • 举报
回复
没问题,我第一个帮你:
在datawindow的Click事件中这样写:
其中:is_OrderCol , is_SortType为窗口的事例变量.
声明为: string is_OrderCol , is_SortType


string ls_AddPict, ls_CurObj, ls_Picture, ls_CurCol
integer li_PictPos

ls_CurObj = String(dwo.Name)
If Row = 0 AND This.Describe(ls_CurObj + ".Text") <> "!" AND This.Describe(ls_CurObj + ".Band") = "header" Then // Valid header object?
ls_CurCol = Left(ls_CurObj,Len(ls_CurObj) - 2)
If is_OrderCol <> ls_CurCol Then // Different Column
is_OrderCol = Left(ls_CurObj,Len(ls_CurObj) - 2)
is_SortType = "A" // Ascending sort
This.SetSort(is_OrderCol + " " + is_SortType)
This.Sort()
Else
If is_SortType = "A" Then
is_SortType = "D"
Else
is_SortType = "A"
End If
This.SetSort(is_OrderCol + " " + is_SortType)
This.Sort()
End If
End If

祝你成功!!!!
不懂再问!!!!

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧