[已解决】请教一下如何判断用户单击选中的是带复选框的listview的哪一行item
本帖最后由 yangsheng1119 于 2011-12-21 23:13 编辑自己翻了几本书都没搞懂,实在没办法了,特来请教listview的选中问题,请各位大哥不吝赐教,谢谢 单击选中行和带不带复选有什么必然关系吗? 回复 2# netegg
--------------------------------------大哥,小弟我就是觉得有个复选框比较专业些,让你见笑了 _GUICtrlListView_GetItemSelected 本帖最后由 xiehuahere 于 2011-12-21 21:00 编辑
回复 1# yangsheng1119
去看看帮助中 _GUICtrlListView_SubItemHitTest 函数说明里的例子吧。
下面是个简化版(不带复选框):
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Const $width = 280, $height = 320
$Form1 = GUICreate("Test", $width, $height, (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2)
$Listview = GUICtrlCreateListView('Column 1|Column 2|Column 3', 7, 60, 266, 161, BitOR($LVS_SINGLESEL, $LVS_REPORT))
$hListView = GUICtrlGetHandle($Listview)
_GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_BORDERSELECT, $LVS_EX_FULLROWSELECT))
For $col = 0 To 2
; Set Text-Centered format for all three columns
_GUICtrlListView_JustifyColumn($hListview, $col, 2)
Next
For $row = 0 To 9
_GUICtrlListView_AddItem($hListview, $row) ; 1st column
_GUICtrlListView_AddSubItem($hListview, $row, 'x_' & $row, 1) ; 2nd column
_GUICtrlListView_AddSubItem($hListview, $row, 'y_' & $row, 2) ; 3rd column
Next
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState(@SW_SHOW)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; http://msdn.microsoft.com/en-us/library/windows/desktop/bb775583(v=vs.85).aspx
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam); $tagNMHDR - Contains information about a notification message
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when user clicks an item with left mouse button
$aHit = _GUICtrlListView_SubItemHitTest($hListView)
MsgBox(0, "", "Item " & $aHit & " is selected") ; Item index is zero based
EndSwitch
EndSwitch
EndFunc
页:
[1]