[已解决]如何让listview里正在处理的行能显示一直可见
本帖最后由 hnfeng 于 2016-6-3 07:40 编辑当listview里面的行很多时,正在处理的行可能跑到在listview下面,看不到,需要拖动滚动条来查看正在处理的行(我使用了 _GUICtrlListView_SetItemSelected 来让正在处理的行变灰色).
有何方法能自动让滚动条移动,以便能刚好显示正在处理的行?
_GUICtrlListView_ClickItem 是可以,但是会影响鼠标在其他程序中的使用(误点击),所以不想使用 _GUICtrlListView_ClickItem
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("Form1", 350, 250)
$ListView1 = GUICtrlCreateListView("", 16, 8, 305, 130, _
BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_BORDER), _
BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
$Button1 = GUICtrlCreateButton("开始", 104, 208, 97, 25)
GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_AddColumn($ListView1, '', 22, 2)
_GUICtrlListView_AddColumn($ListView1, 'aaa', 60, 0)
_GUICtrlListView_AddColumn($ListView1, 'bbb', 40, 0)
_GUICtrlListView_AddColumn($ListView1, 'ccc', 40, 2)
_GUICtrlListView_AddColumn($ListView1, 'ddd', 40, 2)
_GUICtrlListView_AddColumn($ListView1, 'eee', 40, 2)
Dim $a_FromIni = [, _
["a", "abffbdf0001|123|0|0"], _
["a", "abffbdf0002|123|0|0"], _
["a", "abffbdf0003|123|0|0"], _
["a", "abffbdf0004|123|0|0"], _
["a", "abffbdf0005|123|0|0"], _
["a", "abffbdf0006|123|0|0"], _
["a", "abffbdf0007|123|0|0"], _
["a", "abffbdf0008|123|0|0"], _
["a", "abffbdf0009|123|0|0"], _
["a", "abffbdf0010|123|0|0"]]
Dim $item, $i
For $i = 1 To $a_FromIni
$item[$i - 1] = GUICtrlCreateListViewItem("" & '|' & $a_FromIni[$i], $ListView1)
ReDim $item[$i + 1]
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
_Main()
Case $ListView1
_GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Main()
For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
Sleep(300)
_GUICtrlListView_SetItemSelected($ListView1, $i) ; 为了指示正在处理的行
If _GUICtrlListView_GetItemText($ListView1, $i, 5) = "" Then
_GUICtrlListView_SetItemText($ListView1, $i, "xx", 5)
Else
_GUICtrlListView_SetItemText($ListView1, $i, "", 5)
EndIf
Next
EndFunc ;==>_Main
回复 1# hnfeng
_GUICtrlListView_EnsureVisible($hWnd, $iIndex, False) 二楼正解,试着自己添加到楼主的代码上实现了效果
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("Form1", 350, 250)
$ListView1 = GUICtrlCreateListView("", 16, 8, 305, 130, _
BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_BORDER), _
BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
$Button1 = GUICtrlCreateButton("开始", 104, 208, 97, 25)
GUISetState(@SW_SHOW)
_GUICtrlListView_RegisterSortCallBack($ListView1)
_GUICtrlListView_AddColumn($ListView1, '', 22, 2)
_GUICtrlListView_AddColumn($ListView1, 'aaa', 60, 0)
_GUICtrlListView_AddColumn($ListView1, 'bbb', 40, 0)
_GUICtrlListView_AddColumn($ListView1, 'ccc', 40, 2)
_GUICtrlListView_AddColumn($ListView1, 'ddd', 40, 2)
_GUICtrlListView_AddColumn($ListView1, 'eee', 40, 2)
Dim $a_FromIni = [, _
["a", "abffbdf0001|123|0|0"], _
["a", "abffbdf0002|123|0|0"], _
["a", "abffbdf0003|123|0|0"], _
["a", "abffbdf0004|123|0|0"], _
["a", "abffbdf0005|123|0|0"], _
["a", "abffbdf0006|123|0|0"], _
["a", "abffbdf0007|123|0|0"], _
["a", "abffbdf0008|123|0|0"], _
["a", "abffbdf0009|123|0|0"], _
["a", "abffbdf0010|123|0|0"]]
Dim $item, $i
For $i = 1 To $a_FromIni
$item[$i - 1] = GUICtrlCreateListViewItem("" & '|' & $a_FromIni[$i], $ListView1)
ReDim $item[$i + 1]
Next
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Button1
_Main()
Case $ListView1
_GUICtrlListView_SortItems($ListView1, GUICtrlGetState($ListView1))
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _Main()
For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
Sleep(300)
_GUICtrlListView_SetItemSelected($ListView1, $i) ; 为了指示正在处理的行
_GUICtrlListView_EnsureVisible($ListView1, $i)
If _GUICtrlListView_GetItemText($ListView1, $i, 5) = "" Then
_GUICtrlListView_SetItemText($ListView1, $i, "xx", 5)
Else
_GUICtrlListView_SetItemText($ListView1, $i, "", 5)
EndIf
Next
EndFunc ;==>_Main
回复 2# kk_lee69
多谢多谢,高手一出手问题瞬间解决.
我在帮助里确实找了很久没找到,因为看到这个命令的解释也没看懂,就略过去了 这个做界面美化的时候用的到。{:face (396):}
页:
[1]