Senten Posted September 26, 2011 Share Posted September 26, 2011 (edited) Hallo zusammen, ich habe zu dem Thema zwar schon etwas gefunden, konnte dort aber nicht ganz herausfiltern was für mich notwendig und was überflüssig ist. Darum frage ich hier nach dem absoluten Basic zu dem Thema Ich versuche gerade irgendwie einen onEventHandler oder eine GUIMsg für eine ListView zu erstellen. Mein Problem ist, wenn ich solch ein Event über GUICtrlSetOnEvent für die ListView erstelle, reagiert sie nur auf einen Klick auf den Rahmen, nicht auf ein Item. Aber genau das möchte ich, dass das Event ausgelöst wird, sobald ich auf ein ListView-Item klicke. Vielen Dank im Voraus Edit: ich würde eine Lösung über die GUI_Msg (Switch/Case) bevorzugen. Danke ^^ Edited September 26, 2011 by Senten Link to comment Share on other sites More sharing options...
hannes08 Posted September 26, 2011 Share Posted September 26, 2011 Hallo Senten, this is an english forum, so you should translate your question to english in order to get proper answers. Or place your questions on www.autoit.de - the german community. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Senten Posted September 26, 2011 Author Share Posted September 26, 2011 (edited) Hallo Senten, this is an english forum, so you should translate your question to english in order to get proper answers. Or place your questions on www.autoit.de - the german community. ooops ^^ sorry i thought i was on autoIT.de xD - So this is the reason why i had to register again ^^' Ok my question was how i can create an onEvent-Handle for Listview-Items. When I use GUICtrlSetOnEvent the Event only reacts on clicks on the title bars and not on the single items. how can i realize that? Furthermore I would prefer a solution using the GUI_Msg Switch/Case. Edited September 26, 2011 by Senten Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 26, 2011 Moderators Share Posted September 26, 2011 Sentan,Here is how to detect doubleclicks on ListView items - whether created by the native or UDF commands. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; Set flag to indicate double click in ListView Global $fDblClk = False $Gui = GUICreate("Test", 400, 250) ; This works with either type of ListView ;#cs $hListView = GUICtrlCreateListView("Items", 2, 2, 220, 196) _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER) GUICtrlCreateListViewItem("Item 1", $hListView) GUICtrlCreateListViewItem("Item 2", $hListView) GUICtrlCreateListViewItem("Item", $hListView) GUICtrlCreateListViewItem("Item 4", $hListView) ;#ce #cs $hListView = _GUICtrlListView_Create($Gui, "Items", 2, 2, 220, 196, $LVS_REPORT) _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_AddItem($hListView, "Item 1",0) _GUICtrlListView_AddItem($hListView, "Item 2",2) _GUICtrlListView_AddItem($hListView, "Item 3",1) _GUICtrlListView_AddItem($hListView, "Item 4",3) #ce GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch ; If an item was double clicked If $fDblClk Then $fDblClk = False $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, _GUICtrlListView_GetSelectedIndices($hWndListView)) & @CRLF) EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK $fDblClk = True EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFuncIf you want to detect clicks, just change the $NM_DBLCLK to $NM_CLICK. But I recommend sticking with the doubleclick - the ListView uses single clicks to set the selected item and I have found that the clicks are sometimes eaten and not passed to the handler. If you are not very used to using GUIRegisterMsg, could I recommend the GUIRegisterMsg tutorial in the Wiki. M23 faldo 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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