Jewtus Posted November 7, 2014 Share Posted November 7, 2014 I have been trying to figure out how to trigger events based on the item selected from a list view. I've found some sample scripts which I was able to adapt, but I can only figure out how to get it to write the value I'm looking for to the console. Here is a sample: expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <ComboConstants.au3> #include <WinApi.au3> #include <GuiListView.au3> GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") EditAnswerGUI() Func EditAnswerGUI() $AnswerGUI = GUICreate("Edit UI", 804, 462, 179, 104) global $QAList = GUICtrlCreateListView("", 7, 8, 785, 201) _GUICtrlListView_InsertColumn($QAList, 0, "Field I", 110) _GUICtrlListView_InsertColumn(-1, 1, "Field II", 100) _GUICtrlListView_InsertColumn(-1, 2, "Field III", 100) _GUICtrlListView_InsertColumn(-1, 3, "Field IV", 100) _GUICtrlListView_InsertColumn(-1, 4, "Field V", 100) _GUICtrlListView_InsertColumn(-1, 5, "Hyperlink", 100) GUICtrlCreateListViewItem('This|Is|A|Test|Now', $QAList) GUICtrlCreateListViewItem('This1|Is1|A1|Test1|Now1', $QAList) $BLInput = GUICtrlCreateInput("", 8, 232, 250, 21) $IssueInput = GUICtrlCreateInput("", 276, 232, 250, 21) $IssueDescriptionInput = GUICtrlCreateInput("", 543, 232, 250, 21) $Category1 = GUICtrlCreateLabel("Field I", 8, 215, 52, 17) $Category2 = GUICtrlCreateLabel("Field II", 276, 215, 55, 17) $Category3 = GUICtrlCreateLabel("Field III", 544, 214, 58, 17) $QuestionLabel = GUICtrlCreateLabel("Field IV", 8, 258, 46, 17) $QuestionInput = GUICtrlCreateInput("", 8, 275, 785, 21) $Answer = GUICtrlCreateLabel("Field V", 9, 299, 39, 17) $AnswerBox = GUICtrlCreateEdit("", 7, 317, 785, 97) $Update = GUICtrlCreateButton("Update", 712, 424, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $QAList ; $selected= StringSplit(_GUICtrlListView_GetItemTextString($QAList), "|", 2)[0] $selected= _GUICtrlListView_GetItemTextString($QAList) _ArrayDisplay($selected) EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $QAlist If Not IsHWnd($QAlist) Then $hWndListView = GUICtrlGetHandle($QAlist) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ConsoleWrite(DllStructGetData($tInfo, "Index") & @LF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY I don't actually understand fully how the WM_Notify function actually works, but it is spitting out the index of the row, which is what I need. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 7, 2014 Moderators Share Posted November 7, 2014 Jewtus,So what is the question: how does the WM_NOTIFY code work, or how to get the content of the selected row? 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...
Jewtus Posted November 7, 2014 Author Share Posted November 7, 2014 Lets start with how to get the content. Once I have a model I can usually figure it out, but I'm pretty lost on it without context. I would rather not use a func to do this but put it right in line as a case statement (case the List view is selected, and it automatically sets the data into the fields of the GUI), but from what I've read, I can't. I know how to do this with a button, but I'm trying to avoid having to click a record and then click a button. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted November 7, 2014 Moderators Solution Share Posted November 7, 2014 Jewtus, how to get the contentJust use the function correctly inside the handler and use the correct method to display the returned data: expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <ComboConstants.au3> #include <WinApi.au3> #include <GuiListView.au3> GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") EditAnswerGUI() Func EditAnswerGUI() $AnswerGUI = GUICreate("Edit UI", 804, 462, 179, 104) global $QAList = GUICtrlCreateListView("", 7, 8, 785, 201) _GUICtrlListView_InsertColumn($QAList, 0, "Field I", 110) _GUICtrlListView_InsertColumn(-1, 1, "Field II", 100) _GUICtrlListView_InsertColumn(-1, 2, "Field III", 100) _GUICtrlListView_InsertColumn(-1, 3, "Field IV", 100) _GUICtrlListView_InsertColumn(-1, 4, "Field V", 100) _GUICtrlListView_InsertColumn(-1, 5, "Hyperlink", 100) GUICtrlCreateListViewItem('This|Is|A|Test|Now', $QAList) GUICtrlCreateListViewItem('This1|Is1|A1|Test1|Now1', $QAList) $BLInput = GUICtrlCreateInput("", 8, 232, 250, 21) $IssueInput = GUICtrlCreateInput("", 276, 232, 250, 21) $IssueDescriptionInput = GUICtrlCreateInput("", 543, 232, 250, 21) $Category1 = GUICtrlCreateLabel("Field I", 8, 215, 52, 17) $Category2 = GUICtrlCreateLabel("Field II", 276, 215, 55, 17) $Category3 = GUICtrlCreateLabel("Field III", 544, 214, 58, 17) $QuestionLabel = GUICtrlCreateLabel("Field IV", 8, 258, 46, 17) $QuestionInput = GUICtrlCreateInput("", 8, 275, 785, 21) $Answer = GUICtrlCreateLabel("Field V", 9, 299, 39, 17) $AnswerBox = GUICtrlCreateEdit("", 7, 317, 785, 97) $Update = GUICtrlCreateButton("Update", 712, 424, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $QAlist If Not IsHWnd($QAlist) Then $hWndListView = GUICtrlGetHandle($QAlist) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ; We need the index because the click has not yet changed the selection $iIndex = DllStructGetData($tInfo, "Index") $sSelected= _GUICtrlListView_GetItemTextString($QAList, $iIndex) ; This returns a string, not an array ConsoleWrite($sSelected & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYOr set a flag in the handler and put the code in the idle loop - a good idea if there is a lot of it or you use a blocking function: expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <ComboConstants.au3> #include <WinApi.au3> #include <GuiListView.au3> ; Declare flag Global $bClick = False GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") EditAnswerGUI() Func EditAnswerGUI() $AnswerGUI = GUICreate("Edit UI", 804, 462, 179, 104) global $QAList = GUICtrlCreateListView("", 7, 8, 785, 201) _GUICtrlListView_InsertColumn($QAList, 0, "Field I", 110) _GUICtrlListView_InsertColumn(-1, 1, "Field II", 100) _GUICtrlListView_InsertColumn(-1, 2, "Field III", 100) _GUICtrlListView_InsertColumn(-1, 3, "Field IV", 100) _GUICtrlListView_InsertColumn(-1, 4, "Field V", 100) _GUICtrlListView_InsertColumn(-1, 5, "Hyperlink", 100) GUICtrlCreateListViewItem('This|Is|A|Test|Now', $QAList) GUICtrlCreateListViewItem('This1|Is1|A1|Test1|Now1', $QAList) $BLInput = GUICtrlCreateInput("", 8, 232, 250, 21) $IssueInput = GUICtrlCreateInput("", 276, 232, 250, 21) $IssueDescriptionInput = GUICtrlCreateInput("", 543, 232, 250, 21) $Category1 = GUICtrlCreateLabel("Field I", 8, 215, 52, 17) $Category2 = GUICtrlCreateLabel("Field II", 276, 215, 55, 17) $Category3 = GUICtrlCreateLabel("Field III", 544, 214, 58, 17) $QuestionLabel = GUICtrlCreateLabel("Field IV", 8, 258, 46, 17) $QuestionInput = GUICtrlCreateInput("", 8, 275, 785, 21) $Answer = GUICtrlCreateLabel("Field V", 9, 299, 39, 17) $AnswerBox = GUICtrlCreateEdit("", 7, 317, 785, 97) $Update = GUICtrlCreateButton("Update", 712, 424, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch ; If flag set If $bClick Then ; Clear flag $bClick = False ; Run code - no need for the index as the click has now selected the item $sSelected= _GUICtrlListView_GetItemTextString($QAList, -1) ConsoleWrite($sSelected & @CRLF) EndIf WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $QAlist If Not IsHWnd($QAlist) Then $hWndListView = GUICtrlGetHandle($QAlist) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $bClick = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYM23  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...
kylomas Posted November 7, 2014 Share Posted November 7, 2014 A slightly more simplified approach... expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <ComboConstants.au3> #include <WinApi.au3> #include <GuiListView.au3> GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $QAlist, $lv_dummy ; define globals outside of functions EditAnswerGUI() Func EditAnswerGUI() local $aTmp $AnswerGUI = GUICreate("Edit UI", 804, 462, 179, 104) $QAlist = GUICtrlCreateListView("", 7, 8, 785, 201) _GUICtrlListView_InsertColumn($QAlist, 0, "Field I", 110) _GUICtrlListView_InsertColumn(-1, 1, "Field II", 100) _GUICtrlListView_InsertColumn(-1, 2, "Field III", 100) _GUICtrlListView_InsertColumn(-1, 3, "Field IV", 100) _GUICtrlListView_InsertColumn(-1, 4, "Field V", 100) _GUICtrlListView_InsertColumn(-1, 5, "Hyperlink", 100) GUICtrlCreateListViewItem('This|Is|A|Test|Now', $QAlist) GUICtrlCreateListViewItem('This1|Is1|A1|Test1|Now1', $QAlist) $BLInput = GUICtrlCreateInput("", 8, 232, 250, 21) $IssueInput = GUICtrlCreateInput("", 276, 232, 250, 21) $IssueDescriptionInput = GUICtrlCreateInput("", 543, 232, 250, 21) $Category1 = GUICtrlCreateLabel("Field I", 8, 215, 52, 17) $Category2 = GUICtrlCreateLabel("Field II", 276, 215, 55, 17) $Category3 = GUICtrlCreateLabel("Field III", 544, 214, 58, 17) $QuestionLabel = GUICtrlCreateLabel("Field IV", 8, 258, 46, 17) $QuestionInput = GUICtrlCreateInput("", 8, 275, 785, 21) $Answer = GUICtrlCreateLabel("Field V", 9, 299, 39, 17) $AnswerBox = GUICtrlCreateEdit("", 7, 317, 785, 97) $Update = GUICtrlCreateButton("Update", 712, 424, 75, 25) $lv_dummy = GUICtrlCreateDummy() ; control to be actioned by Notify routine GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $lv_dummy ConsoleWrite(_GUICtrlListView_GetItemTextString($QAlist, -1) & @LF) ; write delimited selected item to console ; this appears to be what you want to do local $aTmp = stringsplit(_GUICtrlListView_GetItemTextString($QAlist, -1),'|',2) guictrlsetdata($BLInput,$aTmp[0]) guictrlsetdata($IssueInput,$aTmp[1]) guictrlsetdata($IssueDescriptionInput,$aTmp[2]) guictrlsetdata($QuestionInput,$aTmp[3]) guictrlsetdata($AnswerBox,$aTmp[4]) EndSwitch WEnd EndFunc ;==>EditAnswerGUI Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Switch $tNMHDR.hwndfrom Case GUICtrlGetHandle($QAlist) ; create handle from control id (native control only, UDF controls create handles) Switch $tNMHDR.Code Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button GUICtrlSendToDummy($lv_dummy) ; process listview by actioning dummy control EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Jewtus Posted November 7, 2014 Author Share Posted November 7, 2014 Thanks guys! I ended up going with: expandcollapse popup#include <SQLite.au3> #include <SQLite.dll.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <IE.au3> #include <ComboConstants.au3> #include <WinApi.au3> #include <GuiListView.au3> ; Declare flag Global $bClick = False GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") EditAnswerGUI() Func EditAnswerGUI() $AnswerGUI = GUICreate("Edit UI", 804, 500, 179, 104) global $QAList = GUICtrlCreateListView("", 7, 8, 785, 201) _GUICtrlListView_InsertColumn($QAList, 0, "Field I", 110) _GUICtrlListView_InsertColumn(-1, 1, "Field II", 100) _GUICtrlListView_InsertColumn(-1, 2, "Field III", 100) _GUICtrlListView_InsertColumn(-1, 3, "Field IV", 100) _GUICtrlListView_InsertColumn(-1, 4, "Field V", 100) _GUICtrlListView_InsertColumn(-1, 5, "Hyperlink", 100) GUICtrlCreateListViewItem('This|Is|A|Test|Now', $QAList) GUICtrlCreateListViewItem('This1|Is1|A1|Test1|Now1', $QAList) $BLInput = GUICtrlCreateLabel("", 8, 232, 250, 21) $IssueInput = GUICtrlCreateLabel("", 276, 232, 250, 21) $IssueDescriptionInput = GUICtrlCreateLabel("", 543, 232, 250, 21) $Category1 = GUICtrlCreateLabel("Category I", 8, 215, 52, 17) $Category2 = GUICtrlCreateLabel("Category II", 276, 215, 55, 17) $Category3 = GUICtrlCreateLabel("Category III", 544, 214, 58, 17) $QuestionLabel = GUICtrlCreateLabel("Question", 8, 258, 46, 17) $QuestionInput = GUICtrlCreateInput("", 8, 275, 785, 21) $Answer = GUICtrlCreateLabel("Answer", 9, 299, 39, 17) $AnswerBox = GUICtrlCreateEdit("", 7, 317, 785, 97) $HyperlinkLabel = GUICtrlCreateLabel("Question", 8, 420, 46, 17) $HyperlinkInput = GUICtrlCreateInput("", 8, 440, 785, 21) $Update = GUICtrlCreateButton("Update", 712, 470, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch ; If flag set If $bClick Then ; Clear flag $bClick = False ; Run code - no need for the index as the click has now selected the item $sSelected= _GUICtrlListView_GetItemTextString($QAList, -1) $sSelected= _GUICtrlListView_GetItemTextString($QAList, -1) $form=StringSplit($sSelected,"|") If $form[1] <> '' Then _ArrayDisplay($form) GUICtrlSetData($BLInput,$form[1]) GUICtrlSetData($IssueInput,$form[2]) GUICtrlSetData($IssueDescriptionInput,$form[3]) GUICtrlSetData($QuestionInput,$form[4]) GUICtrlSetData($AnswerBox,$form[5]) GUICtrlSetData($HyperlinkInput,$form[6]) EndIf EndIf WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $QAlist If Not IsHWnd($QAlist) Then $hWndListView = GUICtrlGetHandle($QAlist) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $bClick = True ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY 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