找回密码
 加入
搜索
查看: 2625|回复: 5

[GUI管理] [已解决]请教如何选中某listviewitem触发事件

[复制链接]
发表于 2011-4-28 20:53:14 | 显示全部楼层 |阅读模式
本帖最后由 kxing 于 2011-4-29 08:58 编辑

我希望在一个listview控件中当焦点选中某item时触发事件。
原本用listbox控件只要case $hList 就ok的,但在listview中无效。
$hForm=guicreate("listview",500,400)
$hListView=guictrlcreatelistview("column",0,0,450,350)
guisetstate()

for $i=1 to 10
guictrlcreatelistviewitem("item "&$i,$hListView)
next

while 1
switch guigetmsg()
case -3
exitloop

case $hListView ;无效
msgbox(0,'ok','您选择了 '&guictrlread($hListView))
endswitch
wend
发表于 2011-4-28 22:31:48 | 显示全部楼层
#include <GuiListView.au3>
#include <WindowsConstants.au3>

GUICreate('', 400, 300)
$ListView1 = GUICtrlCreateListView('1', 5, 5, 390, 280)
_GUICtrlListView_SetColumnWidth($ListView1, 0, 380)

For $i = 1 To 10
        GUICtrlCreateListViewItem('项目 - ' & $i, $ListView1)
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Do
Until GUIGetMsg() = -3

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
        $tNMTV = DllStructCreate($tagNMTVDISPINFO, $ilParam)
        $iCode = DllStructGetData($tNMTV, "Code")
        $iIndex = GUICtrlRead($ListView1)
        Switch $iCode
                Case $NM_CLICK
                        If ($iIndex) Then
                                $ItemText = GUICtrlRead($iIndex)
                                MsgBox(0, '项目文本:', $ItemText)
                        EndIf
        EndSwitch
        $tNMTV = 0
EndFunc   ;==>WM_NOTIFY
 楼主| 发表于 2011-4-29 08:58:21 | 显示全部楼层
还是得用 WM_NOTIFY
多谢水木子了哦。。。。。
 楼主| 发表于 2011-4-29 09:00:20 | 显示全部楼层
不行,鼠标单击可以了。
但是光标选中时无法触发,还是我说漏了。抱歉!!!
真正要的是上下光标选中时能触发事件。。。
发表于 2011-4-29 09:15:13 | 显示全部楼层
回复 4# kxing

WM_NOTIFY 所包含的消息非常多,应该有你需要的,你找找吧!

如:$LVN_ITEMCHANGED 、 $LVN_ITEMCHANGING 等!
发表于 2011-4-29 10:51:06 | 显示全部楼层
这个是事件模式吧
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-8 21:09 , Processed in 0.081239 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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