dar100111 Posted December 26, 2013 Share Posted December 26, 2013 (edited) Hey All, I wasn't sure how to take a certain columns info from my listview and put that info into another label (ex. my $sug_label) on my Gui after I click on the result I want from my listview when I get my results from my little search engine I created. Wasn't sure what the GuiGetMsg() would be after clicking on the listview and highlighting my data. Was wondering if anyone could point me in the right direction. Code attached and Thanks! expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=mcw.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 Author: myName Script Function: MID CODE WIZARD #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <Array.au3> $DB_PATH = "F:\EI\DFW\BPM\SQLite\MID_CODE\MID_CODE" $status_message = "Enter Info and Search" _SQLite_Startup() _SQLite_Open($DB_PATH) If @error = -1 Then MsgBox("Connection Failed", "MID CODE Database not opened", "Check MID CODE Database location") #Region ### START Koda GUI section ### Form=c:\users\dfw-danielro\documents\autoit scripts\multi-input-listview.kxf $MCW = GUICreate("MCW", 532, 340, 338, 171) GUISetFont(8, 400, 0, "MS UI Gothic") $title = GUICtrlCreateLabel("Mid Code Wizard", 96, 0, 163, 28, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 14, 800, 0, "@Microsoft JhengHei UI") GUICtrlSetColor(-1, 0x000000) $ListView = GUICtrlCreateListView(" MIDCODE | FACTORY NAME | ADDRESS | CITY | COUNTRY ", 16, 176, 500, 150) GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") $a = GUICtrlCreateInput("", 120, 40, 100, 19, $GUI_SS_DEFAULT_INPUT) $b = GUICtrlCreateInput("", 120, 64, 100, 19, $GUI_SS_DEFAULT_INPUT) $c = GUICtrlCreateInput("", 120, 88, 100, 19, $GUI_SS_DEFAULT_INPUT) $d = GUICtrlCreateInput("", 120, 112, 100, 19, $GUI_SS_DEFAULT_INPUT) $Label1 = GUICtrlCreateLabel("Country", 16, 40, 54, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label2 = GUICtrlCreateLabel("Manufacturer", 16, 64, 89, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label3 = GUICtrlCreateLabel("City", 16, 88, 29, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label4 = GUICtrlCreateLabel("Address #", 16, 112, 64, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $search = GUICtrlCreateButton("Search", 248, 40, 89, 25, $BS_FLAT) GUICtrlSetFont(-1, 10, 400, 0, "@Microsoft JhengHei UI") $sug_label = GUICtrlCreateLabel("", 128, 56, 4, 4, BitOR($SS_CENTER,$SS_CENTERIMAGE,$SS_SUNKEN)) $Label6 = GUICtrlCreateLabel("", 128, 56, 4, 4) $Label5 = GUICtrlCreateLabel("Suggested Mid Code", 240, 72, 113, 18, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "@Microsoft JhengHei UI") $Status_box = GUICtrlCreateLabel($status_message, 16, 152, 338, 18, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") $Label8 = GUICtrlCreateLabel("", 236, 104, 116, 28, BitOR($SS_CENTER,$SS_CENTERIMAGE,$SS_SUNKEN)) GUICtrlSetFont(-1, 10, 400, 0, "MS UI Gothic") ;$Button1 = GUICtrlCreateButton("Create New", 264, 208, 81, 49) ;GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Local $aResult, $iRows, $iColumns, $iRval $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $search _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView)) ;ConsoleWrite('>Error code: ' & @error & @crlf & @crlf & '@@ Trace(71) : _GUICtrlListView_DeleteAllItems($ListView)' & @crlf) ;### Trace Console If ControlGetText($MCW, "", $a) = "" AND ControlGetText($MCW, "", $b) = "" AND ControlGetText($MCW, "", $c) = "" AND ControlGetText($MCW, "", $d) = "" Then MsgBox("Enter Info", "Missing Info", "Please fill out at least one field to query") GUICtrlSetData($Status_box, "Enter Info and Search") else GUICtrlSetData($Status_box, "Running Search") $query_starting_string = "SELECT * FROM MID_INFO WHERE " $ent_country = StringUpper(ControlGetText($MCW, "", $a)) $ent_manufacturer = StringUpper(ControlGetText($MCW, "", $b)) $ent_city = StringUpper(ControlGetText($MCW, "", $c)) $ent_address = StringUpper(ControlGetText($MCW, "", $d)) ;set query $SQLQUERY = "SELECT MIDCODE, FACTORY_NAME, ADDRESS, CITY, COUNTRY FROM ( SELECT [CO_MATCH] + [ADDRESS_MATCH] + [NAME_MATCH] + [CITY_MATCH] AS MATCHES, (SELECT MAX(CASE WHEN X.[Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '' THEN 1 ELSE 0 END) FROM MID_INFO X WHERE (X.[Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '') OR (X.[Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '') OR (X.[Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '') OR (X.[City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '')) AS BLAH, * FROM ( SELECT CASE WHEN [Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '' THEN 1 ELSE 0 END AS [CO_MATCH], CASE WHEN [Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '' THEN 1 ELSE 0 END AS [ADDRESS_MATCH], CASE WHEN [Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '' THEN 1 ELSE 0 END AS [NAME_MATCH], CASE WHEN [City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '' THEN 1 ELSE 0 END AS [CITY_MATCH], * FROM MID_INFO WHERE ([Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '') OR ([Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '') OR ([Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '') OR ([City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '') ) AS BASE ORDER BY [CO_MATCH] + [ADDRESS_MATCH] + [NAME_MATCH] + [CITY_MATCH] DESC) AS BASE2 WHERE MATCHES >= BLAH" _SQLite_GetTable2d(-1, $SQLQUERY, $aResult, $iRows, $iColumns) _ArrayDelete($aResult, 0);delete header row $status_message = "Returned " &UBound($aResult)&" results";return results and display in label GUICtrlSetData($Status_box, $status_message) _GUICtrlListView_AddArray($ListView, $aResult) EndIf EndSwitch WEnd _SQLite_Close() _SQLite_Shutdown() Edited December 26, 2013 by dar100111 Link to comment Share on other sites More sharing options...
l3ill Posted December 26, 2013 Share Posted December 26, 2013 (edited) Hi dar100111, I cant test your code but you will need to look at: _GUICtrlListView_GetSelectedIndices to get the selected text _GUICtrlListView_GetItemText to get the text from the return of that ^ and then send that info to your label with GuiCtrlSetData Let me know if thats not clear. Bill Edit; SnippetBrowser from my sig uses these functions so you can have a look at it for reference. Edited December 26, 2013 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
BrewManNH Posted December 26, 2013 Share Posted December 26, 2013 Look at the help file examples for _GUICtrlListView_Create. The example script for that function shows a lot of different Windows' messages that can be used with listviews, uncomment them and play around with them. Perhaps one of them will do what you need it to do. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
dar100111 Posted December 27, 2013 Author Share Posted December 27, 2013 Very good! I will go play around with those examples. Thanks! Link to comment Share on other sites More sharing options...
dar100111 Posted December 27, 2013 Author Share Posted December 27, 2013 (edited) I used the function WM_NOTIFY from the help file and was able to put my actions in the function to apply when it recognized the click to perform my action. Answer in code below. Thanks for pointing me in the right direction guys! Just had to add in GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") above the loop. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=mcw.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 Author: myName Script Function: MID CODE WIZARD #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <Array.au3> $DB_PATH = "F:\EI\DFW\BPM\SQLite\MID_CODE\MID_CODE" $status_message = "Enter Info and Search" $mid_selected = "" _SQLite_Startup() _SQLite_Open($DB_PATH) If @error = -1 Then MsgBox("Connection Failed", "MID CODE Database not opened", "Check MID CODE Database location") #Region ### START Koda GUI section ### Form=c:\users\dfw-danielro\documents\autoit scripts\multi-input-listview.kxf $MCW = GUICreate("Mid Code Wizard", 532, 340, 338, 171) GUISetFont(8, 400, 0, "MS UI Gothic") ;$title = GUICtrlCreateLabel("Enter Information below", 96, 0, 300, 28, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "@Microsoft JhengHei UI") GUICtrlSetColor(-1, 0x000000) $ListView = GUICtrlCreateListView(" MIDCODE | FACTORY NAME | ADDRESS | CITY | COUNTRY ", 16, 176, 500, 150) GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") $a = GUICtrlCreateInput("", 120, 40, 100, 19, $GUI_SS_DEFAULT_INPUT) $b = GUICtrlCreateInput("", 120, 64, 100, 19, $GUI_SS_DEFAULT_INPUT) $c = GUICtrlCreateInput("", 120, 88, 100, 19, $GUI_SS_DEFAULT_INPUT) $d = GUICtrlCreateInput("", 120, 112, 100, 19, $GUI_SS_DEFAULT_INPUT) $Label1 = GUICtrlCreateLabel("Country", 16, 40, 54, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label2 = GUICtrlCreateLabel("Manufacturer", 16, 64, 89, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label3 = GUICtrlCreateLabel("City", 16, 88, 29, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $Label4 = GUICtrlCreateLabel("Address #", 16, 112, 64, 21, BitOR($SS_RIGHT,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 10, 800, 0, "@Microsoft JhengHei UI") $search = GUICtrlCreateButton("Search", 298, 40, 89, 25, $BS_FLAT) GUICtrlSetFont(-1, 10, 400, 0, "@Microsoft JhengHei UI") $Label5 = GUICtrlCreateLabel("Suggested Mid Code", 290, 72, 113, 18, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 800, 0, "@Microsoft JhengHei UI") $Status_box = GUICtrlCreateLabel($status_message, 16, 152, 338, 18, BitOR($SS_CENTER,$SS_CENTERIMAGE)) GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") $mid_selected_label = GUICtrlCreateLabel("", 298, 104, 116, 28, BitOR($SS_CENTER,$SS_CENTERIMAGE,$SS_SUNKEN)) GUICtrlSetFont(-1, 10, 400, 0, "MS UI Gothic") ;$Button1 = GUICtrlCreateButton("Create New", 264, 208, 81, 49) ;GUICtrlSetFont(-1, 8, 400, 0, "@Microsoft JhengHei UI") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") #EndRegion ### END Koda GUI section ### While 1 Local $aResult, $iRows, $iColumns, $iRval $nMsg = GUIGetMsg() Local $searchdone $searchdone = 0 Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $search _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView)) ;ConsoleWrite('>Error code: ' & @error & @crlf & @crlf & '@@ Trace(71) : _GUICtrlListView_DeleteAllItems($ListView)' & @crlf) ;### Trace Console If ControlGetText($MCW, "", $a) = "" AND ControlGetText($MCW, "", $b) = "" AND ControlGetText($MCW, "", $c) = "" AND ControlGetText($MCW, "", $d) = "" Then MsgBox("Enter Info", "Missing Info", "Please fill out at least one field to query") GUICtrlSetData($Status_box, "Enter Info and Search") else GUICtrlSetData($Status_box, "Running Search") $query_starting_string = "SELECT * FROM MID_INFO WHERE " $ent_country = StringUpper(ControlGetText($MCW, "", $a)) $ent_manufacturer = StringUpper(ControlGetText($MCW, "", $b)) $ent_city = StringUpper(ControlGetText($MCW, "", $c)) $ent_address = StringUpper(ControlGetText($MCW, "", $d)) ;set query $SQLQUERY = "SELECT MIDCODE, FACTORY_NAME, ADDRESS, CITY, COUNTRY FROM ( SELECT [CO_MATCH] + [ADDRESS_MATCH] + [NAME_MATCH] + [CITY_MATCH] AS MATCHES, (SELECT MAX(CASE WHEN X.[Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '' THEN 1 ELSE 0 END + CASE WHEN X.[City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '' THEN 1 ELSE 0 END) FROM MID_INFO X WHERE (X.[Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '') OR (X.[Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '') OR (X.[Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '') OR (X.[City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '')) AS BLAH, * FROM ( SELECT CASE WHEN [Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '' THEN 1 ELSE 0 END AS [CO_MATCH], CASE WHEN [Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '' THEN 1 ELSE 0 END AS [ADDRESS_MATCH], CASE WHEN [Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '' THEN 1 ELSE 0 END AS [NAME_MATCH], CASE WHEN [City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '' THEN 1 ELSE 0 END AS [CITY_MATCH], * FROM MID_INFO WHERE ([Country] LIKE "&"'%"&$ent_country&"%'"&" AND TRIM("&"'"&$ent_country&"'"&") <> '') OR ([Address] LIKE "&"'%"&$ent_address&"%'"&" AND TRIM("&"'"&$ent_address&"'"&") <> '') OR ([Factory_Name] LIKE "&"'%"&$ent_manufacturer&"%'"&" AND TRIM("&"'"&$ent_manufacturer&"'"&") <> '') OR ([City] LIKE "&"'%"&$ent_city&"%'"&" AND TRIM("&"'"&$ent_city&"'"&") <> '') ) AS BASE ORDER BY [CO_MATCH] + [ADDRESS_MATCH] + [NAME_MATCH] + [CITY_MATCH] DESC) AS BASE2 WHERE MATCHES >= BLAH" _SQLite_GetTable2d(-1, $SQLQUERY, $aResult, $iRows, $iColumns) _ArrayDelete($aResult, 0);delete header row $status_message = "Returned " &UBound($aResult)&" results";return results and display in label GUICtrlSetData($Status_box, $status_message) _GUICtrlListView_AddArray($ListView, $aResult) $searchdone = 1 EndIf Case $WM_NOTIFY EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $ListView If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView) local Static $nl=1 local Static $nr=1 $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode ;Enter executions off of actions to gui below Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $selected_row = _GUICtrlListView_GetSelectedIndices($ListView) ;_ArrayDisplay($selected_row) If IsArray($aResult) then $mid_selected = $aResult[$selected_row][0] GUICtrlSetData($mid_selected_label, $mid_selected) ;MsgBox("", "", $mid_selected) Else ;MsgBox("", "", "no search") EndIf Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY _SQLite_Close() _SQLite_Shutdown() Edited December 27, 2013 by dar100111 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