#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