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

[AU3基础] [已解决]如何让listview里正在处理的行能显示一直可见

[复制链接]
发表于 2016-6-2 21:21:41 | 显示全部楼层 |阅读模式
本帖最后由 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[11][2] = [[10, ""], _
                ["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[1], $i
For $i = 1 To $a_FromIni[0][0]
        $item[$i - 1] = GUICtrlCreateListViewItem("" & '|' & $a_FromIni[$i][1], $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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-6-2 23:33:55 | 显示全部楼层
回复 1# hnfeng

_GUICtrlListView_EnsureVisible($hWnd, $iIndex, False)

评分

参与人数 1金钱 +10 收起 理由
chamlien + 10 厉害、佩服

查看全部评分

发表于 2016-6-3 01:08:37 | 显示全部楼层
二楼正解,试着自己添加到楼主的代码上实现了效果

#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[11][2] = [[10, ""], _
                ["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[1], $i
For $i = 1 To $a_FromIni[0][0]
        $item[$i - 1] = GUICtrlCreateListViewItem("" & '|' & $a_FromIni[$i][1], $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
 楼主| 发表于 2016-6-3 07:34:19 | 显示全部楼层
回复 2# kk_lee69


    多谢多谢,高手一出手问题瞬间解决.
我在帮助里确实找了很久没找到,因为看到这个命令的解释也没看懂,就略过去了
发表于 2016-6-6 23:56:05 | 显示全部楼层
这个做界面美化的时候用的到。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 03:34 , Processed in 0.285302 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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