Beornhardt Posted October 22, 2013 Share Posted October 22, 2013 Hi there! I'm new to this forum, and quite new to AutoIt. I created a GUI with two ListViews on it, whose Lines should be clickable. Now, here's my question: How do I detect, which ListView was clicked on, and from this ListView, which element was clicked? I already figured out how to work out the click on one of the Items in the first ListView... (Posting the whole code would be a bit much, as it is about 5000 Lines already... ) Thanks in advance for your efforts B. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted October 22, 2013 Moderators Solution Share Posted October 22, 2013 Beornhardt,Welcome to the AutoIt forum. I do not recommend looking for single clicks on ListViews as in my experience they are often eaten by the control itself - I always suggest looking for doubleclicks. And this is how you might do it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GUIListView.au3> Global $fClick = 0, $iLV, $iRow, $iCol $hGUI = GUICreate("Test", 500, 500) $cLV_1 = GUICtrlCreateListView("", 10, 10, 230, 300) _GUICtrlListView_AddColumn($cLV_1, "Col 0", 100) _GUICtrlListView_AddColumn($cLV_1, "Col 1", 100) For $i = 0 To 25 GUICtrlCreateListViewItem("Item 1" & $i & "0|Item 1" & $i & "1", $cLV_1) Next $hLV_1_Handle = GUICtrlGetHandle($cLV_1) $cLV_2 = GUICtrlCreateListView("", 260, 10, 230, 300) _GUICtrlListView_AddColumn($cLV_2, "Col 0", 100) _GUICtrlListView_AddColumn($cLV_2, "Col 1", 100) For $i = 0 To 25 GUICtrlCreateListViewItem("Item 2" & $i & "0|Item 2" & $i & "1", $cLV_2) Next $hLV_2_Handle = GUICtrlGetHandle($cLV_2) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY_Handler") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Look for click flag If $fClick Then ; Display result MsgBox($MB_SYSTEMMODAL, "Clicked", "LV:" & @TAB & $iLV & @CRLF & "Row:" & @TAB & $iRow & @CRLF & "Col:" & @TAB & $iCol) ; Clear flag $fClick = 0 EndIf WEnd Func _WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Switch DllStructGetData($tStruct, 1) Case $hLV_1_Handle $iLV = 1 Case $hLV_2_Handle $iLV = 2 Case Else Return EndSwitch If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = $NM_DBLCLK Then $iRow = DllStructGetData($tStruct, 4) $iCol = DllStructGetData($tStruct, 5) ; Set flag $fClick = 1 EndIf EndFuncI realise this is not exactly a simple script - so please ask if you have any questions. M23 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...
Beornhardt Posted October 22, 2013 Author Share Posted October 22, 2013 Hey, thanks a lot for the quick reply! This does exactly what I need! I just have a Question for my understanding. When you do this: Switch DllStructGetData($tStruct, 1) are you querying the hwnd or the uint_ptr from the struct? (And: You were absolutely right: This is not exactly a 'simple script' ... Best regards B. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 22, 2013 Moderators Share Posted October 22, 2013 Beornhardt,The struct has 5 components - these are referenced from 1 to 5. So 1 refers to the hWnd section, as shown by the fact that I check it against the handles of the ListViews. Similarly, the item/subitem are in sections 4 and 5 (the 2 integer values at the end). M23 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...
Beornhardt Posted October 22, 2013 Author Share Posted October 22, 2013 That's brilliant! Thank's a lot! B. 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