timor Posted June 6, 2008 Posted June 6, 2008 Hello, I'm writing a little app in guionevent mode and I need to get action when left clicking on listview. I'm quite new in AutoIt so any help will be helpful. Thanks.
rasim Posted June 6, 2008 Posted June 6, 2008 See _GUICtrlListView_Create() function example in the help file.
timor Posted June 6, 2008 Author Posted June 6, 2008 One more thing... I'm using listview controls witch checkboxes and in this event it could be action on checkbox check.
timor Posted June 6, 2008 Author Posted June 6, 2008 This example uses Message Loop mode, is there any way to do this in onevent mode (it's more convenient for me)?
rasim Posted June 7, 2008 Posted June 7, 2008 Example: #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> Opt("GuiOnEventMode", 1) $hGUI = GUICreate("Test GUI", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $ListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, -1, BitOR($LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)) For $i = 1 To 10 GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $ListView) GUICtrlSetOnEvent(-1, "_GetChecked") Next GUISetState() While 1 Sleep(100) WEnd Func _Exit() Exit EndFunc Func _GetChecked() If GUICtrlRead(@GUI_CtrlId, 1) = 1 Then ConsoleWrite(GUICtrlRead(@GUI_CtrlId) & " is checked" & @LF) EndFunc
timor Posted June 13, 2008 Author Posted June 13, 2008 (edited) Thanks, for that few lines. Works perfect. One more thing. For now it works when I click on Item (using mouse), is there an easy way to get it working with keyboard actions? Edited June 13, 2008 by timor
rasim Posted June 14, 2008 Posted June 14, 2008 Try this: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <StructureConstants.au3> Opt("GuiOnEventMode", 1) $hGUI = GUICreate("Test GUI", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $ListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, -1, BitOR($LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)) For $i = 1 To 10 _GUICtrlListView_AddItem($ListView, "Item " & $i) _GUICtrlListView_AddSubItem($ListView, $i - 1, "SubItem " & $i, 1) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() While 1 Sleep(100) WEnd Func _Exit() Exit EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hListView, $tNMHDR, $hWndFrom, $iCode $hListView = $ListView If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($ListView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iItem = DllStructGetData($tInfo, "Item") If _GUICtrlListView_GetItemChecked($hListView, $iItem) = True Then ConsoleWrite("---> Item " & $iItem + 1 & " has checked" & @LF) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc
rasim Posted June 14, 2008 Posted June 14, 2008 Or this: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <Misc.au3> Opt("GuiOnEventMode", 1) Global $DllHandle = DllOpen("user32.dll") $hGUI = GUICreate("Test GUI", 300, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $ListView = GUICtrlCreateListView("Items|SubItems", 10, 10, 280, 180, -1, BitOR($LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)) For $i = 1 To 10 GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $ListView) GUICtrlSetOnEvent(-1, "_GetChecked") Next GUISetState() While 1 If _IsPressed("20", $DllHandle) Then _Check() Sleep(100) EndIf Sleep(100) WEnd Func _Exit() DllClose($DllHandle) Exit EndFunc Func _GetChecked() If GUICtrlRead(@GUI_CtrlId, 1) = 1 Then ConsoleWrite(GUICtrlRead(@GUI_CtrlId) & " is checked" & @LF) EndFunc Func _Check() Local $iItem = _GUICtrlListView_GetSelectedIndices($ListView) If $iItem = "" Then Return False If _GUICtrlListView_GetItemChecked($ListView, $iItem) Then ConsoleWrite("Item " & $iItem + 1 & " is checked" & @LF) EndFunc
nikink Posted June 18, 2008 Posted June 18, 2008 Hmmm, how do you differentiate between two listviews (or more) on the same gui that have the same on-click functionality?
rasim Posted June 18, 2008 Posted June 18, 2008 nikinkFunc WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView_1 ;Some action Case $hListView_2 ;Some action Case $hListView_3 ;Some action EndSwitch Return $GUI_RUNDEFMSG EndFunc
nikink Posted June 18, 2008 Posted June 18, 2008 D'oh! Of course! I feel really dumb now... I've been trying to follow the examples in the help file and been caught up in the way they use $hListView all the time... didn't even occur to me to do the obvious case setup like you just posted. Thanks!
topten Posted August 12, 2014 Posted August 12, 2014 Very nice solution! One question If GUICtrlRead(@GUI_CtrlId, 1) = 1 Then ConsoleWrite(GUICtrlRead(@GUI_CtrlId) & " is checked" & @LF) Is it possible to trace if it was unchecked? I was trying If GUICtrlRead(@GUI_CtrlId, 1) =0 Then ConsoleWrite(GUICtrlRead(@GUI_CtrlId) & " is unchecked" & @LF) doesnt work Thanx in advance!
MikahS Posted August 12, 2014 Posted August 12, 2014 @topten take out the 1 in your call to If GUICtrlRead(@GUI_CtrlId) = 0 See if that does the trick. I think it is giving back more information then just 0 when 1 is set to return extended info on the ctrl. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
topten Posted August 12, 2014 Posted August 12, 2014 Ah, great! Thank you very much for such a fast reply! Yes, this way works better- allows to register if checked and unchecked
MikahS Posted August 12, 2014 Posted August 12, 2014 @topten glad to help Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now