找回密码
 加入
搜索
查看: 3883|回复: 4

[GUI管理] [已解决]如何根据索引将右侧滑块定位到listview相应的位置?

[复制链接]
发表于 2014-10-12 14:14:14 | 显示全部楼层 |阅读模式
本帖最后由 ioripalm 于 2014-12-28 14:20 编辑

listview查找到项目时,已经做好了搜到的所有项目行都高亮,但是项目很多,导致查找起来很不方便,如何做几个按钮,比如说“上一个,下一个”来将右侧的滑块快速定位到我想要到的位置。
发表于 2014-10-12 16:11:39 | 显示全部楼层
#include <GuiListView.au3>
_GUICtrlListView_GetItemPosition ( $hWnd, $iIndex )

#include <GuiListView.au3>
_GUICtrlListView_Scroll ( $hWnd, $iDX, $iDY )
发表于 2014-10-13 02:17:50 | 显示全部楼层
回复 2# vigiles

完全所答非所问嘛
发表于 2014-10-13 09:27:58 | 显示全部楼层
回复 3# netegg
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>


$wH = GUICreate("", 300, 200)
        $lvH = GUICtrlCreateListView ( " -- 列 1 -- | -- 列 2 -- | -- 列 3 -- ", 5, 5, 290, 150 )
                $lviItem01 = GUICtrlCreateListViewItem(" 行 01-1 | 行01-2 | 行01-3 ", $lvH)
                $lviItem02 = GUICtrlCreateListViewItem(" 行 02-1 | 行02-2 | 行02-3 ", $lvH)
                $lviItem03 = GUICtrlCreateListViewItem(" 行 03-1 | 行03-2 | 行03-3 ", $lvH)
                $lviItem04 = GUICtrlCreateListViewItem(" 行 04-1 | 行04-2 | 行04-3 ", $lvH)
                $lviItem05 = GUICtrlCreateListViewItem(" 行 05-1 | 行05-2 | 行05-3 ", $lvH)
                $lviItem06 = GUICtrlCreateListViewItem(" 行 06-1 | 行06-2 | 行06-3 ", $lvH)
                $lviItem07 = GUICtrlCreateListViewItem(" 行 07-1 | 行07-2 | 行07-3 ", $lvH)
                $lviItem08 = GUICtrlCreateListViewItem(" 行 08-1 | 行08-2 | 行08-3 ", $lvH)
                $lviItem09 = GUICtrlCreateListViewItem(" 行 09-1 | 行09-2 | 行09-3 ", $lvH)
                $lviItem10 = GUICtrlCreateListViewItem(" 行 10-1 | 行10-2 | 行10-3 ", $lvH)
                $lviItem11 = GUICtrlCreateListViewItem(" 行 11-1 | 行11-2 | 行11-3 ", $lvH)
                $lviItem12 = GUICtrlCreateListViewItem(" 行 12-1 | 行12-2 | 行12-3 ", $lvH)
                $lviItem13 = GUICtrlCreateListViewItem(" 行 13-1 | 行13-2 | 行13-3 ", $lvH)
                $lviItem14 = GUICtrlCreateListViewItem(" 行 14-1 | 行14-2 | 行14-3 ", $lvH)
                $lviItem15 = GUICtrlCreateListViewItem(" 行 15-1 | 行15-2 | 行15-3 ", $lvH)

                _GUICtrlListView_SetItemSelected ( $lvH, 8, True, True )                                        ;演示行,第9行,被选中高亮

                $iSelected = _GUICtrlListView_GetSelectedIndices ( $lvH, True )                                ; 1.获取选中的行
                $pSelected = _GUICtrlListView_GetItemPosition ( $lvH, $iSelected[1] )                ; 2.获得选中行的坐标
                _GUICtrlListView_Scroll ( $lvH, $pSelected[0], $pSelected[1]-60 )                        ; 3.定位。每行约高30

        $btnprevious = GUICtrlCreateButton("上一个", 5,   165, 60, 30)
        $btnNext     = GUICtrlCreateButton("下一个", 235, 165, 60, 30)

GUISetState(@SW_SHOW, $wH)

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop

                Case $btnprevious
                        $iSelected = _GUICtrlListView_GetSelectedIndices ( $lvH, True )                                ; 1.获取选中的行
                        $pSelected = _GUICtrlListView_GetItemPosition ( $lvH, $iSelected[1]-1 )                ; 2.获得选中行的坐标
                        _GUICtrlListView_Scroll ( $lvH, $pSelected[0], $pSelected[1]-60 )                        ; 3.定位。减去60,在本例中近似居中。

                        _GUICtrlListView_SetItemSelected ( $lvH, $iSelected[1]-1, True )                ; 选中行

                Case $btnNext        ;----> bug,到最后一行,继续点击按钮,会向上滚动。
                        $iSelected = _GUICtrlListView_GetSelectedIndices ( $lvH, True )                                ; 1.获取选中的行
                        $pSelected = _GUICtrlListView_GetItemPosition ( $lvH, $iSelected[1]+1 )                ; 2.获得选中行的坐标
                        _GUICtrlListView_Scroll ( $lvH, $pSelected[0], $pSelected[1]-60 )                        ; 3.定位

                        _GUICtrlListView_SetItemSelected ( $lvH, $iSelected[1]+1, True, True )                ; 选中行

        EndSwitch
WEnd
发表于 2014-10-25 14:45:43 | 显示全部楼层
好贴,一定要收藏,呵呵~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 13:21 , Processed in 0.079981 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表