Biatu Posted January 6, 2018 Share Posted January 6, 2018 Just for aesthetics, one of my UI concepts for an updater had a Listview with with available updates, and I wanted to put a button in a right most column to view the update notes. Another one was a Todo list with 3 buttons for task specific actions. Personally I think this would be better than needing to click on an item then on a button off on the edge of the ListView What is what? What is what. Link to comment Share on other sites More sharing options...
BigDaddyO Posted February 21, 2018 Share Posted February 21, 2018 I just tried to run one of my existing scripts in the new version of AutoIT and I got an error as part of the _GUIListViewEx_EditOnClick() function. error: _WinAPI_GetAsyncKeyState(): undefined function  Adding #include <WinAPISys.au3> to the top of the GUIListViewEx.au3 resolved the problem. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 21, 2018 Author Moderators Share Posted February 21, 2018 (edited) BigDaddyO, jpm strikes again with his repackaging of the more obscure WinAPI functions - sorry about that. I think I will just add a suitable "internal use only" function ( all 4 lines of it!) to the UDF rather then add a 1500+ line include file. Look out for a new release in the UDF thread shortly. In future, could you post any problems with my UDFs in the associated thread because it is much easier to notice them then as opposed to a post somewhere in GH&S M23 Edit; There are actually another couple of WinAPI functions in the UDF the locations of which jpm has rearranged - just checking again. Edited February 21, 2018 by Melba23  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...
BigDaddyO Posted February 21, 2018 Share Posted February 21, 2018 I have been using these so much, I forgot they were UDF's and not normal Functions. Great UDF's by the way! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2018 Author Moderators Share Posted February 22, 2018 BigDaddyO, It got too complicated to add all the WinAPI functions internally, so I will go with the simple added include file that you suggested and hope jpm does not fiddle with the locations again in the near future! Thanks for the report - and delighted you like my UDFs. M23 P.S. I will merge this thread into the main UDF one when I have released the new version later today.  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...
Moderators Melba23 Posted February 22, 2018 Author Moderators Share Posted February 22, 2018 [NEW VERSION] - 22 Feb 18 Changed: Added an include file to cater for a rearrangement of the WinAPI functions in v3.3.14.3. New UDF in the first post. 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...
x_bennY Posted March 7, 2018 Share Posted March 7, 2018 (edited) Hey @Melba23 I'm using your UDF and i have one doubt. When i drag and drop an item it resizes the columns and i don't want it! How could i disable this? Edited March 7, 2018 by x_bennY Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 7, 2018 Author Moderators Share Posted March 7, 2018 x_bennY, Please provide me with a small reproducer script and a set of instructions so that I can see just what you are doing. M23 x_bennY 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...
x_bennY Posted March 8, 2018 Share Posted March 8, 2018 (edited) Hi @Melba23 Sorry for not being clear. Here is the script: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example Global $iCount_Left = 20, $iCount_Right = 20, $vData, $sMsg, $aLV_List_Left, $aLV_List_Right, $aRet, $iEditMode = 0 ; Create GUI $hGUI = GUICreate("LVEx Example 1", 640, 510) ; Create Left ListView GUICtrlCreateLabel("Native ListView", 10, 5, 300, 30) $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300) _GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT) ; Set font GUICtrlSetFont($cListView_Left, 12, Default, Default, "Courier New") ; Note edit control will use same font ; Create array and fill Left listview Global $aLV_List_Left[$iCount_Left] For $i = 0 To UBound($aLV_List_Left) - 1 If Mod($i, 5) Then $aLV_List_Left[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i Else $aLV_List_Left[$i] = "Tom " & $i & "||Harry " & $i EndIf GUICtrlCreateListViewItem($aLV_List_Left[$i], $cListView_Left) Next ; Initiate LVEx - use filling array - no count parameter - default insert mark colour (black) - drag image - sortable + not select all text + editable headers $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 0, 0, True, 1 + 2 + 8) _GUIListViewEx_MsgRegister() GUISetState() ; Set the left ListView as active _GUIListViewEx_SetActive(1) _GUICtrlListView_SetColumnWidth($cListView_Left, 0, 50) _GUICtrlListView_SetColumnWidth($cListView_Left, 1, 50) _GUICtrlListView_SetColumnWidth($cListView_Left, 2, 50) msgbox(0,0, "Drag n drop one of the itemns to see what happens...") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSe Exit endswitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 4 msgbox(0,0, "The columns width changes.") EndSwitch WEnd  Edited March 8, 2018 by x_bennY Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 8, 2018 Author Moderators Share Posted March 8, 2018 (edited) x_bennY, That is an unfortunate "feature" of the ListView control - it tries to display the full width of all items when they are inserted - and nothing to do with my UDF as such. I added an optional parameter for inserting elements which automatically reset the column widths - you can do something similar in the short term: <snip> I will take a look and see if I can get the UDF to do this automatically for drag/drop by using an optional parameter somewhere. M23 Edit: Actually a pretty easy fix to get the UDF to do this - I am assuming that all column widths will remain constant when drag/drop is used. Try this Beta version and let me know what you think: Edited May 10, 2020 by Melba23 Beta code removed x_bennY 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...
x_bennY Posted March 8, 2018 Share Posted March 8, 2018 @Melba23 Wow! excellent as always! this is exactly what i was talking about. Don't know how to thank.... Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted June 20, 2018 Share Posted June 20, 2018 Hi there, if i enable colors for the items in the listview I need to register the message handler. But this registration disables the possibility to select multiple items in the listview, or am I doing something wrong? Â #include <Array.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" $hGUI = GUICreate("Coloured ListView Example", 400, 400) $iLvw = GUICtrlCreateListView("Col 1|Col 2|Col 3|Col 4", 5, 5, 390, 390, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS)) For $iRow = 0 To 5 $sData = "Item " & $iRow & "-0" For $iCol = 1 To 3 $sData &= "|SubItem " & $iRow & "-" & $iCol Next GUICtrlCreateListViewItem($sData, $iLvw) Next Local $iLvw_Inx = _GUIListViewEx_Init($iLvw, "", 0, 0, True, 32 + 512) _GUIListViewEx_SetColour($iLvw_Inx, ";0xF0FF00", 0, 0) _GUIListViewEx_SetColour($iLvw_Inx, ";0xF0FFAF", 2, 2) _GUIListViewEx_MsgRegister() GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Thanks for your help and the great UDF :-) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 20, 2018 Author Moderators Share Posted June 20, 2018 HurleyShanabarger, Using colour forces single row/item selection - sorry about that. 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...
HurleyShanabarger Posted June 22, 2018 Share Posted June 22, 2018 (edited) On 20.6.2018 at 4:13 PM, Melba23 said: HurleyShanabarger, Using colour forces single row/item selection - sorry about that. M23 No need to be sorry - sometimes things are just the way they are :-) Edited June 22, 2018 by HurleyShanabarger Link to comment Share on other sites More sharing options...
robertocm Posted July 21, 2018 Share Posted July 21, 2018 (edited)  Dear all, I'm trying to use _GUIListViewEx_GetLastSelItem function to get the index of the highlighted item in the ListView on each selection change. An example of this function would be very appreciated Many Thanks Below is an update of an example that i'm using to learn about the UDF: it looks for a name in a MS Access table and display results in the listview. Here the access database file to test the example: db.mdb expandcollapse popup#include <GuiConstants.au3> #include <EditConstants.au3> #include <GuiMenu.au3> ;GUIListViewEx from Melba23 https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16 #include "GUIListViewEx.au3" ;Gui adapted From Ayman Henry (aymhenry@gmail.com), Phone Book Rev 02 ;Sorry but do not remember where _GUI_ToTray function was found nor the name of the author #Include <Constants.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) Opt("TrayIconHide", 1) Opt( "MustDeclareVars", 1 ) ;_ErrADODB From spudw2k ;https://www.autoitscript.com/forum/topic/105875-adodb-example/ Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Local Const $sTitle = "Phone Book" Const $conOK = 1, $conEdit = 1, $conAdd = 0 Global $cmdAdd, $cmdEdit, $cmdDelete, $cmdCancel Global $cmdNext, $cmdFirst, $cmdPrev, $cmdLast Global $cmdSave Global $InStr Global $n_RecCount, $n_RecPos ; Sreen Fields Global $txtFirstName, $txtMidName, $txtLastName Global $txtMobile, $txtHomePhone, $txtAddress Global $lblRecPos Global $sFilePath = @ScriptDir & "\db.mdb" Global $sAnswer, $TempAr Global $sSQL Global Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilePath ;Global $sADOConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" $cn.CursorLocation = 3 ; adUseClient $cn.Open($sADOConnectionString) ; Open the connection Global $tblname = "Tel", $w Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77 Global Enum $idExit = 1000, $idFavorites, $idCustomFavs1, $idCustomFavs2 Global $hGui, $hMenu Local $hFile, $hCustomFavs, $hPrograms, $hCustomProgs ;Create GUI $hGui = GUICreate($sTitle, $GuiWidth, $GuiHight) GUISetBkColor(0xA9A9A9) ;Register a function for WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Create File menu $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hFile, 0, "Exit", $idExit) ;This is from LarsJ: ShowFavsProgsMenu. Create custom Favorites menu. $hCustomFavs = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hCustomFavs, 0, "AutoIt", $idCustomFavs1) _GUICtrlMenu_InsertMenuItem($hCustomFavs, 1, "Microsoft", $idCustomFavs2) ; Create Main menu $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "File", 0, $hFile) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Favorites", $idFavorites) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Custom Favorites", 0, $hCustomFavs) ;Set window menu _GUICtrlMenu_SetMenu($hGui, $hMenu) Local $Label1, $Label2, $Label3, $Label4, $Label5, $Label6 $Label1 = GUICtrlCreateLabel("N", 8, 45, 20, 20) $Label2 = GUICtrlCreateLabel("T1", 8, 81, 20, 20) $Label3 = GUICtrlCreateLabel("T2", 8, 117, 20, 20) $Label4 = GUICtrlCreateLabel("T3", 8, 153, 20, 20) $Label5 = GUICtrlCreateLabel("T4", 8, 189, 20, 20) $Label6 = GUICtrlCreateLabel("A", 8, 225, 20, 20) Global $KeyW = GUICtrlCreateInput("", 30, 2, 205, 33) GUICtrlSetBkColor(-1, 0xD3D3D3) GUICtrlSetFont(-1, 12) $txtFirstName = GUICtrlCreateInput("", 30, 40, 1130, 30) GUICtrlSetLimit(-1, 200) GUICtrlSetFont(-1, 14) $txtMidName = GUICtrlCreateInput("", 30, 76, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 14) $txtLastName = GUICtrlCreateInput("", 30, 112, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtMobile = GUICtrlCreateInput("", 30, 148, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtHomePhone = GUICtrlCreateInput("", 30, 184, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtAddress = GUICtrlCreateInput("", 30, 220, 1130, 30) GUICtrlSetLimit(-1, 250) GUICtrlSetFont(-1, 12) ;This is from Melba23 GUIListViewEx Local $vRet Global $cLV, $iLV, $iEditMode = 22 $cLV = GUICtrlCreateListView("Name|T1|T2|T3", 2, 255, $GuiWidth-4, 530) ;$cLV = GUICtrlCreateListView("Name|T1|T2|T3", 2, 255, $GuiWidth-4, 440, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) ;_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) ;Set font GUICtrlSetFont($cLV, 12, Default, Default, "Courier New") ; Note edit control will use same font _GUICtrlListView_SetColumnWidth($cLV, 0, 600) _GUICtrlListView_SetColumnWidth($cLV, 1, 250) _GUICtrlListView_SetColumnWidth($cLV, 2, 250) _GUICtrlListView_SetColumnWidth($cLV, 3, 250) ;Initiate GLVEx - no array passed - count parameter set - default insert mark colour (black) - drag image $iLV = _GUIListViewEx_Init($cLV, "", 1, 0, True, 4) ;All columns editable _GUIListViewEx_SetEditStatus($iLV, "*") ;Insert blank rows ;For $i = 0 To 9 ; _GUIListViewEx_Insert("") ;Next ;_GUIListViewEx_SetEditKey("20") ;SPACEBAR $cmdFirst = GUICtrlCreateButton("|<", 250, 2, 33, 33, 0) $cmdPrev = GUICtrlCreateButton("<", 286, 2, 33, 33, 0) $lblRecPos = GUICtrlCreateLabel("", 318, 8, 80, 24, $ES_CENTER) GUICtrlSetFont(-1, 11) $cmdNext = GUICtrlCreateButton(">", 396, 2, 33, 33, 0) $cmdLast = GUICtrlCreateButton(">|", 432, 2, 33, 33, 0) $cmdAdd = GUICtrlCreateButton("Add", 1170, 40, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdEdit = GUICtrlCreateButton("Edit", 1170, 76, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdDelete = GUICtrlCreateButton("Delete", 1170, 112, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdSave = GUICtrlCreateButton("Save", 1170, 148, 92, 31, 0) $cmdCancel = GUICtrlCreateButton("Cancel", 1170, 184, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) #cs ;Now trying to detect the index of highlighted item in the ListView ;From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF': The UDF registers 4 messages automatically – if you already have message handlers in your script, do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False) but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler. ;Here an example from Melba23: https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933 #ce ;$hLV = GUICtrlGetHandle($cLV) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ;Register for editing & dragging ;prevent the UDF from initially registering the WM_NOTIFY _GUIListViewEx_MsgRegister(False) GUISetState(@SW_SHOW) GUICtrlSetState($KeyW, $GUI_FOCUS) ;Set the left ListView as active ;_GUIListViewEx_SetActive(1) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Shtdown() GUIDelete( $hGui ) Exit Case $GUI_EVENT_MINIMIZE ;; -4 _GUI_ToTray() Case $KeyW OnFilt() Case $cmdNext cmdNext_Click() Case $cmdPrev cmdPrev_Click() Case $cmdFirst cmdFirst_Click() Case $cmdLast cmdLast_Click() Case $cmdAdd cmdAdd_Click() Case $cmdEdit cmdEdit_CLick() Case $cmdDelete cmdDelete_Click() Case $cmdSave cmdSave_Click() Case $cmdCancel cmdCancel_Click() EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 0 ;No event detected Case 1 If $vRet = "" Then ;MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else ;_ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8) MsgBox($MB_SYSTEMMODAL, "", $vRet[1][3]) MsgBox($MB_SYSTEMMODAL, "", _GUIListViewEx_GetLastSelItem()) ;ListViewIndex|Row|Col EndIf EndSwitch WEnd ;From Zedna, in 'Highlighted item in the ListView?' ;https://www.autoitscript.com/forum/topic/96234-highlighted-item-in-the-listview/?do=findComment&comment=691927 Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $cLV Switch $Code Case $LVN_ITEMCHANGED Local $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then ;Local $Item = _GUICtrlListView_GetItem($cLV, $Index) ;ConsoleWrite("Index:" & @TAB & $Index & @CRLF & "Item:" & @TAB & $Item[3] & @CR) GUICtrlSetData($txtFirstName, $aLV[$Index][0]) GUICtrlSetData($txtMidName, $aLV[$Index][1]) GUICtrlSetData($txtLastName, $aLV[$Index][2]) GUICtrlSetData($txtMobile, $aLV[$Index][3]) GUICtrlSetData($txtHomePhone, $aLV[$Index][4]) GUICtrlSetData($txtAddress, $aLV[$Index][5]) GUICtrlSetData($lblRecPos, $Index + 1 & " of " & $n_RecCount) $n_RecPos = $Index EndIf EndIf EndSwitch EndSwitch ;Return $GUI_RUNDEFMSG ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler: ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_NOTIFY Func OnFilt() $sAnswer = GUICtrlRead($KeyW) GUICtrlSetData($KeyW, "") If $sAnswer <> "" Then $w = " WHERE N LIKE '%" & $sAnswer & "%'" $sSQL = "SELECT * FROM " & $tblname & $w $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ;Issue the SQL query #cs Global $aLV[100][6] Local $f = 0 If Not $rst.EOF Then With $rst While Not .EOF ; repeat until End-Of-File (EOF) is reached $aLV[$f][0]=.Fields(0).Value $aLV[$f][1]=.Fields(1).Value $aLV[$f][2]=.Fields(2).Value $aLV[$f][3]=.Fields(3).Value $aLV[$f][4]=.Fields(4).Value $aLV[$f][5]=.Fields(5).Value .MoveNext ; Move To the Next record $f = $f + 1 WEnd EndWith EndIf $rst.Close $n_RecCount = UBound($aLV) ReDim $aLV[$f][6] #ce If $rst.EOF = True Then $rst.Close Return -3 EndIf Global $aLV = $rst.GetRows() $rst.Close $n_RecCount = UBound($aLV) Else $n_RecCount = 0 EndIf If $n_RecCount = 0 Then cmdAdd_Click() Else ;reload the ListView with new data, first clear the current content _GUICtrlListView_DeleteAllItems($cLV) ;close it within the UDF _GUIListViewEx_Close(0) ;reload the ListView with the new data _GUICtrlListView_AddArray($cLV, $aLV) ;Initiate LVEx - using filling array $iLV = _GUIListViewEx_Init($cLV, $aLV, 0, 0, True, 4) ;Set all columns editable _GUIListViewEx_SetEditStatus($iLV, "*") KeysSetup(0) cmdFirst_Click() EndIf EndFunc Func ShowData() If $n_RecCount = 0 Then ; Blank Table GUICtrlSetData($lblRecPos, "") GUICtrlSetData($txtFirstName, "") GUICtrlSetData($txtMidName, "") GUICtrlSetData($txtLastName, "") GUICtrlSetData($txtMobile, "") GUICtrlSetData($txtHomePhone, "") GUICtrlSetData($txtAddress, "") Return EndIf GUICtrlSetData($lblRecPos, $n_RecPos + 1 & " of " & $n_RecCount) GUICtrlSetData($txtFirstName, $aLV[$n_RecPos][0]) GUICtrlSetData($txtMidName, $aLV[$n_RecPos][1]) GUICtrlSetData($txtLastName, $aLV[$n_RecPos][2]) GUICtrlSetData($txtMobile, $aLV[$n_RecPos][3]) GUICtrlSetData($txtHomePhone, $aLV[$n_RecPos][4]) GUICtrlSetData($txtAddress, $aLV[$n_RecPos][5]) EndFunc Func cmdAdd_Click() $n_RecCount = 0 ShowData() KeysSetup(1) GUICtrlSetState($txtFirstName, $GUI_FOCUS) EndFunc Func cmdEdit_Click() $InStr = GUICtrlRead($txtFirstName) KeysSetup(1) EndFunc Func cmdCancel_Click() If $n_RecCount = 0 Then ; Blank Table Return EndIf ShowData() KeysSetup(0) GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdSave_Click() If $InStr <> "" Then $sSQL = "DELETE FROM Tel WHERE N = '" & $InStr & "'" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 EndIf $sSQL = "INSERT INTO Tel (N, T1, T2, T3, T4, D) VALUES ('" & GUICtrlRead($txtFirstName) & "', '" & GUICtrlRead($txtMidName) & "', '" & GUICtrlRead($txtLastName) & "', '" & GUICtrlRead($txtMobile) & "', '" & GUICtrlRead($txtHomePhone) & "', '" & GUICtrlRead($txtAddress) & "')" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 KeysSetup(0) GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdDelete_Click() If 6 = MsgBox(32 + 4, "Delete", "Are you sure delete the current record Permanently?") Then $sSQL = "DELETE FROM Tel WHERE N = '" & GUICtrlRead($txtFirstName) & "'" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 $n_RecCount = 0 ShowData() KeysSetup(1) EndIf GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdNext_Click() $n_RecPos = $n_RecPos + 1 If $n_RecPos = $n_RecCount Then $n_RecPos = $n_RecCount - 1 If $n_RecPos < 0 Then $n_RecPos = 0 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdPrev_Click() $n_RecPos = $n_RecPos - 1 If $n_RecPos < 0 Then $n_RecPos = 0 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdFirst_Click() $n_RecPos = 0 ShowData() EndFunc Func cmdLast_Click() $n_RecPos = $n_RecCount -1 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func Shtdown() ; Close conexion ;$rst.Close $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object EndFunc Func _GUI_ToTray() GUISetState(@SW_HIDE, $hGui) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_GUI_Restore") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_Quit") TrayTip($sTitle, "Left click to restore" & @CRLF & "Right click to Exit", 5, 1) TraySetToolTip($sTitle & @CRLF & @CRLF & "Left click to restore" & @CRLF & "Right click to Exit") TraySetToolTip("") Opt("TrayIconHide", 0) Return $hGui EndFunc ;==>_GUI_ToTray Func _GUI_Restore() GUISetState(@SW_SHOW, $hGui) WinActivate($hGui) TraySetState(2) Opt("TrayIconHide", 1) EndFunc ;==>_GUI_Restore Func _Quit() Shtdown() Exit EndFunc ;==>_Quit Func KeysSetup($lngMode) Local $nState1, $nState2 Local $n_State, $n_Color, $n_Cursor If $lngMode = 1 Then ; Blank Table $nState1 = $GUI_ENABLE $nState2 = $GUI_DISABLE $n_State = Not $ES_READONLY $n_Color = 0x000000 $n_Cursor = 5 Else $nState1 = $GUI_DISABLE $nState2 = $GUI_ENABLE $n_State = $ES_READONLY $n_Color = 0x0000ff $n_Cursor = 2 EndIf GUICtrlSetState($cmdSave, $nState1) GUICtrlSetState($cmdAdd, $nState2) GUICtrlSetState($cmdEdit, $nState2) GUICtrlSetState($cmdCancel, $nState1) GUICtrlSetState($cmdDelete, $nState2) GUICtrlSetState($cmdNext, $nState2) GUICtrlSetState($cmdPrev, $nState2) GUICtrlSetState($cmdFirst, $nState2) GUICtrlSetState($cmdLast, $nState2) ; Screen Fields GUICtrlSetStyle($txtFirstName, $n_State) GUICtrlSetStyle($txtMidName, $n_State) GUICtrlSetStyle($txtLastName, $n_State) GUICtrlSetStyle($txtMobile, $n_State) GUICtrlSetStyle($txtHomePhone, $n_State) GUICtrlSetStyle($txtAddress, $n_State) GUICtrlSetColor($txtFirstName, $n_Color) GUICtrlSetColor($txtMidName, $n_Color) GUICtrlSetColor($txtLastName, $n_Color) GUICtrlSetColor($txtMobile, $n_Color) GUICtrlSetColor($txtHomePhone, $n_Color) GUICtrlSetColor($txtAddress, $n_Color) GUICtrlSetColor($txtFirstName, $n_Color) GUICtrlSetColor($txtMidName, $n_Color) GUICtrlSetColor($txtLastName, $n_Color) GUICtrlSetColor($txtMobile, $n_Color) GUICtrlSetColor($txtHomePhone, $n_Color) GUICtrlSetColor($txtAddress, $n_Color) GUICtrlSetCursor($txtFirstName, $n_Cursor) GUICtrlSetCursor($txtMidName, $n_Cursor) GUICtrlSetCursor($txtLastName, $n_Cursor) GUICtrlSetCursor($txtMobile, $n_Cursor) GUICtrlSetCursor($txtHomePhone, $n_Cursor) GUICtrlSetCursor($txtAddress, $n_Cursor) EndFunc Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) ; high word Local $nID = BitAND($wParam, 0xFFFF) ; low word Local $hCtrl = $lParam Switch $nID Case $idExit Shtdown() Exit Case $idFavorites Msgbox(0, "", "This is only an example") Case $idCustomFavs1 Msgbox(0, "", "This would be same action") Case $idCustomFavs2 Msgbox(0, "", "Last example") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cn.Close $cn = 0 Exit EndFunc  Edited July 21, 2018 by robertocm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 22, 2018 Author Moderators Share Posted July 22, 2018 robertocm, At present you are using _GUIListViewEx_GetLastSelItem inside the _GUIListViewEx_EventMonitor Switch structure when @extended is set to 1 - this only happens when en edit operation has occurred and so will not fire on a simple selection change. Here is a short example script where you check on every pass for a change in selection - and also get notice of which cell was edited (although for a successful edit this info is already returned by _GUIListViewEx_EventMonitor): expandcollapse popup#include <GuiConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GUIListViewEx.au3" Global $sCoords = "", $sPrevCoords = "" ; Create GUI $hGUI = GUICreate("LVEx Example GetLastSel", 640, 510) ; Create ListView $cListView = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($cListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) _GUICtrlListView_SetColumnWidth($cListView, 0, 93) _GUICtrlListView_SetColumnWidth($cListView, 1, 93) _GUICtrlListView_SetColumnWidth($cListView, 2, 93) ; Create array and fill Left listview Global $aLV_List[10] For $i = 0 To UBound($aLV_List) - 1 $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i GUICtrlCreateListViewItem($aLV_List[$i], $cListView) Next ; Initiate LVEx $iLV_Index = _GUIListViewEx_Init($cListView, $aLV_List) _GUIListViewEx_SetEditStatus($iLV_Index, "*") $cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110) ; Register for sorting, dragging and editing _GUIListViewEx_MsgRegister() GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $cExit_Button Exit EndSwitch $vRet = _GUIListViewEx_EventMonitor() If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 1 ; This is returned after an edit attempt $sCoords = _LastSel() If $sCoords Then If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted at " & $sCoords & @CRLF) Else MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit at " & $sCoords & @CRLF) EndIf EndIf EndSwitch ; To check for selection only, you need to check like this $sCoords = _LastSel() If $sCoords <> $sPrevCoords Then MsgBox($MB_SYSTEMMODAL,"Selection changed", "Selected: " & $sCoords) $sPrevCoords = $sCoords EndIf WEnd Func _LastSel() Local $sSelCoords = "" $sLastSel = _GUIListViewEx_GetLastSelItem() $aSplit = StringSplit($sLastSel, "|") If Not @error Then $sSelCoords = $aSplit[2] & " - " & $aSplit[3] EndIf Return $sSelCoords EndFunc I hope that clears up any confusion - please ask again if not. 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...
Moderators Melba23 Posted July 22, 2018 Author Moderators Share Posted July 22, 2018 (edited) robertocm, It is not difficult to amend the UDF to indicate a selection change using _EventMonitor - would this be better for you? Here is the beta UDF: <snip> And here is an example script showing it in action: <snip> M23 Edited July 23, 2018 by Melba23 Beta code removed  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...
robertocm Posted July 22, 2018 Share Posted July 22, 2018 (edited) Many Thanks!! This is perfect Only a little detail: it seems that the returned value in $vRet is a string Then for the row component, seems we have to use: StringSplit($vRet, "|")[2] I would suggest to return an array in order to simplify the access of the row component  Also it seems that inserting an empty row with _GUIListViewEx_Insert("") makes the _EventMonitor to return 9 , but with a value for the row = -1 I think it would be better not returning 9 in this case, because there is not a user selection change. Here an improved version of the 'phone book' example using the beta version of the UDF. Added the possibility to edit the database records directly from the listview expandcollapse popup#include <GuiConstants.au3> #include <EditConstants.au3> #include <GuiMenu.au3> ;GUIListViewEx from Melba23 https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16 #include "GUIListViewEx.au3" ;Gui adapted From Ayman Henry (aymhenry), Phone Book Rev 02 ;Sorry but do not remember where _GUI_ToTray function was found nor the name of the author #Include <Constants.au3> Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) Opt("TrayIconHide", 1) Opt( "MustDeclareVars", 1 ) ;_ErrADODB From spudw2k ;https://www.autoitscript.com/forum/topic/105875-adodb-example/ Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Local Const $sTitle = "Phone Book" Const $conOK = 1, $conEdit = 1, $conAdd = 0 Global $cmdAdd, $cmdEdit, $cmdDelete, $cmdCancel Global $cmdNext, $cmdFirst, $cmdPrev, $cmdLast Global $cmdSave Global $InStr Global $n_RecCount, $n_RecPos ;Sreen Fields Global $txtFirstName, $txtMidName, $txtLastName Global $txtMobile, $txtHomePhone, $txtAddress Global $lblRecPos Global $sFilePath = @ScriptDir & "\db.mdb" Global $sAnswer, $sSQL, $w, $rstArray, $tblname = "Tel" Global Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic Global Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Global Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilePath ;Global $sADOConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" $cn.CursorLocation = 3 ; adUseClient $cn.Open($sADOConnectionString) ; Open the connection Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77 Global Enum $idExit = 1000, $idFavorites, $idCustomFavs1, $idCustomFavs2 Global $hGui, $hMenu Local $hFile, $hCustomFavs, $hPrograms, $hCustomProgs ;Create GUI $hGui = GUICreate($sTitle, $GuiWidth, $GuiHight) GUISetBkColor(0xA9A9A9) ;Register a function for WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Create File menu $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hFile, 0, "Exit", $idExit) ;This is from LarsJ: ShowFavsProgsMenu. Create custom Favorites menu. $hCustomFavs = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hCustomFavs, 0, "AutoIt", $idCustomFavs1) _GUICtrlMenu_InsertMenuItem($hCustomFavs, 1, "Microsoft", $idCustomFavs2) ; Create Main menu $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "File", 0, $hFile) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Favorites", $idFavorites) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Custom Favorites", 0, $hCustomFavs) ;Set window menu _GUICtrlMenu_SetMenu($hGui, $hMenu) Local $Label1, $Label2, $Label3, $Label4, $Label5, $Label6 $Label1 = GUICtrlCreateLabel("N", 8, 45, 20, 20) $Label2 = GUICtrlCreateLabel("T1", 8, 81, 20, 20) $Label3 = GUICtrlCreateLabel("T2", 8, 117, 20, 20) $Label4 = GUICtrlCreateLabel("T3", 8, 153, 20, 20) $Label5 = GUICtrlCreateLabel("T4", 8, 189, 20, 20) $Label6 = GUICtrlCreateLabel("A", 8, 225, 20, 20) Global $KeyW = GUICtrlCreateInput("", 30, 2, 205, 33) GUICtrlSetBkColor(-1, 0xD3D3D3) GUICtrlSetFont(-1, 12) $txtFirstName = GUICtrlCreateInput("", 30, 40, 1130, 30) GUICtrlSetLimit(-1, 200) GUICtrlSetFont(-1, 14) $txtMidName = GUICtrlCreateInput("", 30, 76, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 14) $txtLastName = GUICtrlCreateInput("", 30, 112, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtMobile = GUICtrlCreateInput("", 30, 148, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtHomePhone = GUICtrlCreateInput("", 30, 184, 1130, 30) GUICtrlSetLimit(-1, 100) GUICtrlSetFont(-1, 12) $txtAddress = GUICtrlCreateInput("", 30, 220, 1130, 30) GUICtrlSetLimit(-1, 250) GUICtrlSetFont(-1, 12) ;This is from Melba23 GUIListViewEx Local $vRet, $Index, $aLV Global $cLV, $iLV, $iEditMode = 22 $cLV = GUICtrlCreateListView("Name|T1|T2|T3|T4|D", 2, 255, $GuiWidth-4, 530) ;$cLV = GUICtrlCreateListView("Name|T1|T2|T3", 2, 255, $GuiWidth-4, 440, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) ;_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) ;Set font GUICtrlSetFont($cLV, 12, Default, Default, "Courier New") ; Note edit control will use same font _GUICtrlListView_SetColumnWidth($cLV, 0, 600) _GUICtrlListView_SetColumnWidth($cLV, 1, 250) _GUICtrlListView_SetColumnWidth($cLV, 2, 250) _GUICtrlListView_SetColumnWidth($cLV, 3, 250) _GUICtrlListView_SetColumnWidth($cLV, 4, 0) _GUICtrlListView_SetColumnWidth($cLV, 5, 0) ;Register required message BEFORE any colour actions (register for sorting, dragging and editing) _GUIListViewEx_MsgRegister() ;Initiate GLVEx - no array passed - not count parameter set - default insert mark colour (black) - drag image $iLV = _GUIListViewEx_Init($cLV, "", 0, 0, True, 4) ;All columns editable _GUIListViewEx_SetEditStatus($iLV, "*") ;Insert blank row: available for inserting a new database record directly from the listview _GUIListViewEx_Insert("") ;_GUIListViewEx_InsertSpec($iLV, -1, "") ;_GUIListViewEx_SetEditKey("20") ;SPACEBAR $cmdFirst = GUICtrlCreateButton("|<", 250, 2, 33, 33, 0) $cmdPrev = GUICtrlCreateButton("<", 286, 2, 33, 33, 0) $lblRecPos = GUICtrlCreateLabel("", 318, 8, 80, 24, $ES_CENTER) GUICtrlSetFont(-1, 11) $cmdNext = GUICtrlCreateButton(">", 396, 2, 33, 33, 0) $cmdLast = GUICtrlCreateButton(">|", 432, 2, 33, 33, 0) $cmdAdd = GUICtrlCreateButton("Add", 1170, 40, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdEdit = GUICtrlCreateButton("Edit", 1170, 76, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdDelete = GUICtrlCreateButton("Delete", 1170, 112, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) $cmdSave = GUICtrlCreateButton("Save", 1170, 148, 92, 31, 0) $cmdCancel = GUICtrlCreateButton("Cancel", 1170, 184, 92, 31, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) GUICtrlSetState($KeyW, $GUI_FOCUS) ;Set the left ListView as active ;_GUIListViewEx_SetActive(1) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Shtdown() GUIDelete( $hGui ) Exit Case $GUI_EVENT_MINIMIZE ;; -4 _GUI_ToTray() Case $KeyW OnFilt() Case $cmdNext cmdNext_Click() Case $cmdPrev cmdPrev_Click() Case $cmdFirst cmdFirst_Click() Case $cmdLast cmdLast_Click() Case $cmdAdd cmdAdd_Click() Case $cmdEdit cmdEdit_CLick() Case $cmdDelete cmdDelete_Click() Case $cmdSave cmdSave_Click() Case $cmdCancel cmdCancel_Click() EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) If @error Then MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error) EndIf Switch @extended Case 1 ; This is returned after an edit attempt If $vRet = "" Then ;MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF) Else ;_ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8) ;MsgBox($MB_SYSTEMMODAL, "", $vRet[1][3]) ;MsgBox($MB_SYSTEMMODAL, "", _GUIListViewEx_GetLastSelItem()) ;ListViewIndex|Row|Col ;updating the access table from the listview $InStr = GUICtrlRead($txtFirstName) Switch $vRet[1][1] ;Column Case 0 GUICtrlSetData($txtFirstName, $vRet[1][3]) Case 1 GUICtrlSetData($txtMidName, $vRet[1][3]) Case 2 GUICtrlSetData($txtLastName, $vRet[1][3]) Case 3 GUICtrlSetData($txtMobile, $vRet[1][3]) Case 4 GUICtrlSetData($txtHomePhone, $vRet[1][3]) Case 5 GUICtrlSetData($txtAddress, $vRet[1][3]) EndSwitch cmdSave_Click() EndIf Case 9 ; This is returned after a selection change ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection: " & $vRet) $Index = StringSplit($vRet, "|")[2] If $Index <> -1 Then ;This is because _GUIListViewEx_Insert makes the _EventMonitor return 9 with a value of row -1 ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New row is: " & StringSplit($vRet, "|")[2]) $aLV = _GUIListViewEx_ReturnArray($iLV, 3) ;_ArrayDisplay($aLV, "current content", Default, 8) GUICtrlSetData($txtFirstName, $aLV[$Index][0]) GUICtrlSetData($txtMidName, $aLV[$Index][1]) GUICtrlSetData($txtLastName, $aLV[$Index][2]) GUICtrlSetData($txtMobile, $aLV[$Index][3]) GUICtrlSetData($txtHomePhone, $aLV[$Index][4]) GUICtrlSetData($txtAddress, $aLV[$Index][5]) GUICtrlSetData($lblRecPos, $Index + 1 & " of " & $n_RecCount) $n_RecPos = $Index EndIf EndSwitch WEnd Func OnFilt() $sAnswer = GUICtrlRead($KeyW) GUICtrlSetData($KeyW, "") If $sAnswer <> "" Then $w = " WHERE N LIKE '%" & $sAnswer & "%'" $sSQL = "SELECT * FROM " & $tblname & $w $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ;Issue the SQL query #cs Global $rstArray[100][6] Local $f = 0 If Not $rst.EOF Then With $rst While Not .EOF ; repeat until End-Of-File (EOF) is reached $rstArray[$f][0]=.Fields(0).Value $rstArray[$f][1]=.Fields(1).Value $rstArray[$f][2]=.Fields(2).Value $rstArray[$f][3]=.Fields(3).Value $rstArray[$f][4]=.Fields(4).Value $rstArray[$f][5]=.Fields(5).Value .MoveNext ; Move To the Next record $f = $f + 1 WEnd EndWith EndIf $rst.Close $n_RecCount = UBound($rstArray) ReDim $rstArray[$f][6] #ce If $rst.EOF = True Then $rst.Close Return -3 EndIf $rstArray = $rst.GetRows() $rst.Close $n_RecCount = UBound($rstArray) Else $n_RecCount = 0 EndIf If $n_RecCount = 0 Then cmdAdd_Click() Else ;reload the ListView with new data, first clear the current content _GUICtrlListView_DeleteAllItems($cLV) ;close it within the UDF _GUIListViewEx_Close(0) ;reload the ListView with the new data _GUICtrlListView_AddArray($cLV, $rstArray) ;Initiate LVEx - using filling array $iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, True, 4) ;Set all columns editable _GUIListViewEx_SetEditStatus($iLV, "*") KeysSetup(0) cmdFirst_Click() EndIf EndFunc Func ShowData() If $n_RecCount = 0 Then ; Blank Table GUICtrlSetData($lblRecPos, "") GUICtrlSetData($txtFirstName, "") GUICtrlSetData($txtMidName, "") GUICtrlSetData($txtLastName, "") GUICtrlSetData($txtMobile, "") GUICtrlSetData($txtHomePhone, "") GUICtrlSetData($txtAddress, "") Return EndIf GUICtrlSetData($lblRecPos, $n_RecPos + 1 & " of " & $n_RecCount) GUICtrlSetData($txtFirstName, $rstArray[$n_RecPos][0]) GUICtrlSetData($txtMidName, $rstArray[$n_RecPos][1]) GUICtrlSetData($txtLastName, $rstArray[$n_RecPos][2]) GUICtrlSetData($txtMobile, $rstArray[$n_RecPos][3]) GUICtrlSetData($txtHomePhone, $rstArray[$n_RecPos][4]) GUICtrlSetData($txtAddress, $rstArray[$n_RecPos][5]) EndFunc Func cmdAdd_Click() $n_RecCount = 0 ShowData() KeysSetup(1) GUICtrlSetState($txtFirstName, $GUI_FOCUS) EndFunc Func cmdEdit_Click() $InStr = GUICtrlRead($txtFirstName) KeysSetup(1) EndFunc Func cmdCancel_Click() If $n_RecCount = 0 Then ; Blank Table Return EndIf ShowData() KeysSetup(0) GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdSave_Click() $cn.BeginTrans If $InStr <> "" Then $sSQL = "DELETE FROM Tel WHERE N = '" & $InStr & "'" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 EndIf $sSQL = "INSERT INTO Tel (N, T1, T2, T3, T4, D) VALUES ('" & GUICtrlRead($txtFirstName) & "', '" & GUICtrlRead($txtMidName) & "', '" & GUICtrlRead($txtLastName) & "', '" & GUICtrlRead($txtMobile) & "', '" & GUICtrlRead($txtHomePhone) & "', '" & GUICtrlRead($txtAddress) & "')" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 $cn.CommitTrans KeysSetup(0) GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdDelete_Click() If 6 = MsgBox(32 + 4, "Delete", "Are you sure delete the current record Permanently?") Then $sSQL = "DELETE FROM Tel WHERE N = '" & GUICtrlRead($txtFirstName) & "'" ;$rst.Open($sSQL, $cn, $iCursorType, $iLockType) $cn.Execute($sSQL, Default, 1 + 0x80) ;adCmdText = 1 , adExecuteNoRecords = 0x80 $n_RecCount = 0 ShowData() KeysSetup(1) EndIf GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdNext_Click() $n_RecPos = $n_RecPos + 1 If $n_RecPos = $n_RecCount Then $n_RecPos = $n_RecCount - 1 If $n_RecPos < 0 Then $n_RecPos = 0 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdPrev_Click() $n_RecPos = $n_RecPos - 1 If $n_RecPos < 0 Then $n_RecPos = 0 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func cmdFirst_Click() $n_RecPos = 0 ShowData() EndFunc Func cmdLast_Click() $n_RecPos = $n_RecCount -1 ShowData() GUICtrlSetState($KeyW, $GUI_FOCUS) EndFunc Func Shtdown() ; Close conexion ;$rst.Close $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object EndFunc Func _GUI_ToTray() GUISetState(@SW_HIDE, $hGui) TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_GUI_Restore") TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_Quit") TrayTip($sTitle, "Left click to restore" & @CRLF & "Right click to Exit", 5, 1) TraySetToolTip($sTitle & @CRLF & @CRLF & "Left click to restore" & @CRLF & "Right click to Exit") TraySetToolTip("") Opt("TrayIconHide", 0) Return $hGui EndFunc ;==>_GUI_ToTray Func _GUI_Restore() GUISetState(@SW_SHOW, $hGui) WinActivate($hGui) TraySetState(2) Opt("TrayIconHide", 1) EndFunc ;==>_GUI_Restore Func _Quit() Shtdown() Exit EndFunc ;==>_Quit Func KeysSetup($lngMode) Local $nState1, $nState2 Local $n_State, $n_Color, $n_Cursor If $lngMode = 1 Then ; Blank Table $nState1 = $GUI_ENABLE $nState2 = $GUI_DISABLE $n_State = Not $ES_READONLY $n_Color = 0x000000 $n_Cursor = 5 Else $nState1 = $GUI_DISABLE $nState2 = $GUI_ENABLE $n_State = $ES_READONLY $n_Color = 0x0000ff $n_Cursor = 2 EndIf GUICtrlSetState($cmdSave, $nState1) GUICtrlSetState($cmdAdd, $nState2) GUICtrlSetState($cmdEdit, $nState2) GUICtrlSetState($cmdCancel, $nState1) GUICtrlSetState($cmdDelete, $nState2) GUICtrlSetState($cmdNext, $nState2) GUICtrlSetState($cmdPrev, $nState2) GUICtrlSetState($cmdFirst, $nState2) GUICtrlSetState($cmdLast, $nState2) ; Screen Fields GUICtrlSetStyle($txtFirstName, $n_State) GUICtrlSetStyle($txtMidName, $n_State) GUICtrlSetStyle($txtLastName, $n_State) GUICtrlSetStyle($txtMobile, $n_State) GUICtrlSetStyle($txtHomePhone, $n_State) GUICtrlSetStyle($txtAddress, $n_State) GUICtrlSetColor($txtFirstName, $n_Color) GUICtrlSetColor($txtMidName, $n_Color) GUICtrlSetColor($txtLastName, $n_Color) GUICtrlSetColor($txtMobile, $n_Color) GUICtrlSetColor($txtHomePhone, $n_Color) GUICtrlSetColor($txtAddress, $n_Color) GUICtrlSetColor($txtFirstName, $n_Color) GUICtrlSetColor($txtMidName, $n_Color) GUICtrlSetColor($txtLastName, $n_Color) GUICtrlSetColor($txtMobile, $n_Color) GUICtrlSetColor($txtHomePhone, $n_Color) GUICtrlSetColor($txtAddress, $n_Color) GUICtrlSetCursor($txtFirstName, $n_Cursor) GUICtrlSetCursor($txtMidName, $n_Cursor) GUICtrlSetCursor($txtLastName, $n_Cursor) GUICtrlSetCursor($txtMobile, $n_Cursor) GUICtrlSetCursor($txtHomePhone, $n_Cursor) GUICtrlSetCursor($txtAddress, $n_Cursor) EndFunc Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) ; high word Local $nID = BitAND($wParam, 0xFFFF) ; low word Local $hCtrl = $lParam Switch $nID Case $idExit Shtdown() Exit Case $idFavorites Msgbox(0, "", "This is only an example") Case $idCustomFavs1 Msgbox(0, "", "This would be same action") Case $idCustomFavs2 Msgbox(0, "", "Last example") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext _ ) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cn.Close $cn = 0 Exit EndFunc  Edited July 22, 2018 by robertocm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 23, 2018 Author Moderators Share Posted July 23, 2018 (edited) robertocm, Good points - try this amended version: <snip> M23 Edited July 28, 2018 by Melba23 Beta code removed  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...
robertocm Posted July 24, 2018 Share Posted July 24, 2018 Many Thank!! 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