图学PowerBuilder---实现Datawindow多选的函数

来源:互联网 发布:idea mac 激活服务器 编辑:程序博客网 时间:2024/06/03 02:26

先上一图看看效果

在PB的Datawindow中不似list等控件,默认不支持多选(CTRL、SHIFT)但可以通过代码来实现。下边就列出多选的实现方法。

补充说明:其它与其它开发工具中的选择行相比较而言,PB的Datawindow中的行默认情况下鼠标点选后,该行并没有选中,而是需要一个Boolean的变量标记行是否选中。

首先要在变量声明中定义如下变量:

代码放在这里,方便大家复制(呵呵)

boolean ib_multiSelect = Truelong il_lastRow=0long il_firstRow=0int ii_current_style = 0
然后定义函数:

然后在函数体中加入如下实现代码:

long lCrint iStepstring ls_CurObj, ls_CurColinteger li_LinePosif isnull(dw.dataobject) or len(string(dw.dataobject)) <= 0 then returnif row <> 0 thenif (ib_multiSelect = True) thenif KeyDown( KeyControl! ) then if dw.isSelected( Row ) = True thendw.SelectRow( Row,False )elsedw.SelectRow( Row,True )dw.SetRow( Row )end ifil_FirstRow = Rowelseif KeyDown( KeyShift! ) thendw.SelectRow( 0,False )if Row > il_FirstRow thenfor lCr = il_FirstRow to Rowif lCr>0 and lCr<=dw.Rowcount() thendw.SelectRow( lCr,True )end ifnextelsefor lCr = il_FirstRow to Row Step -1if lCr>0 and lCr<=dw.Rowcount() thendw.SelectRow( lCr,True )end ifnextend ifelsedw.SelectRow( 0,False )dw.SelectRow( Row,True )dw.SetRow( Row )il_FirstRow = Rowend ifend if  elsedw.SelectRow( 0,False )if ii_current_style = 0 thendw.SelectRow( Row,True )end ifdw.SetRow( Row )il_FirstRow = Rowend ifend if

最后在Datawindow的Clicked中调用此方法即可:


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

原来搜索了一个类似的方法,但有些问题,感谢秦哥提供了方法,在那之上调整了通用的Datawindow