algospider Posted April 7, 2019 Posted April 7, 2019 Hello everyone, this is my first post in the forum, so apologize if this might not be the right section. I am using the GUIListViewEx UDF from @Melba23 (thx for that awesome UDF!) I started creating a simple CRUD (Create-Update-Delete) Application, based on one of the provided examples, and I am struggling to create the "Create" When pressing the Create button, I created another form that appears. I would like to use this form to add a new entry into the table. However, I am struggling how to read the values and add them to the table. Please find below my minimum viable example. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> #include <UpDownConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <Misc.au3> #include <String.au3> #include <Array.au3> #include "GUIListViewEx.au3" Global $sRet $hGUI = GUICreate("Task Table Helper", 750, 510) ; Create ListView GUICtrlCreateLabel("Task Table", 10, 10, 400, 20) $cLV_1 = GUICtrlCreateListView("#|Title|Image|Post|Schedule Date|Status", 10, 30, 720, 260, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetExtendedListViewStyle($cLV_1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV_1, $i, 100) Next ; Create array and fill listview Global $aLVArray_1[8][6] ; Initiate ListView = sort on column click - editable headers - header colours - user colours $iLVIndex_1 = _GUIListViewEx_Init($cLV_1, $aLVArray_1, 0, 0, True, 1 + 8 + 32) ; + 16 ; Set column edit status _GUIListViewEx_SetEditStatus($iLVIndex_1, 1) ; Default = standard text edit _GUIListViewEx_SetEditStatus($iLVIndex_1, 2, 2, "1|2|3", True) ; 2 = Read-only combo _GUIListViewEx_SetEditStatus($iLVIndex_1, 3, 3) ; 3 = DTP _GUIListViewEx_SetEditStatus($iLVIndex_1, 4) ; Default = standard text edit ; Create buttons for LH ListView GUICtrlCreateGroup("", 10, 300, 480, 160) GUICtrlCreateLabel("Up/Down", 25, 320, 80, 20, $SS_CENTER) $cUp = GUICtrlCreateButton("Up", 25, 340, 80, 30) $cDown = GUICtrlCreateButton("Down", 25, 380, 80, 30) GUICtrlCreateLabel("Row", 150, 320, 80, 20, $SS_CENTER) $cIns = GUICtrlCreateButton("Insert", 150, 340, 80, 30) $cDel = GUICtrlCreateButton("Delete", 150, 380, 80, 30) $cCre = GUICtrlCreateButton("Create", 150, 420, 80, 30) GUICtrlCreateLabel("Run/Stop", 275, 320, 80, 20, $SS_CENTER) $cRun = GUICtrlCreateButton("Run", 275, 340, 80, 30) $cStop = GUICtrlCreateButton("Stop", 275, 380, 80, 30) GUICtrlCreateLabel("Read", 400, 320, 80, 20, $SS_CENTER) $cContent = GUICtrlCreateButton("Content", 400, 340, 80, 30) $cHeaders = GUICtrlCreateButton("Headers", 400, 380, 80, 30) ; Create additional buttons $cSave = GUICtrlCreateButton("Save LH ListView", 10, 470, 150, 30) $cLoad = GUICtrlCreateButton("Load RH ListView", 180, 470, 150, 30) GUICtrlSetState($cLoad, $GUI_DISABLE) $cExit = GUICtrlCreateButton("Exit", 360, 470, 110, 30) ; If colours used then this function must be run BEFORE GUISetState _GUIListViewEx_MsgRegister() GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $cExit MsgBox(0, "Close", "SAVE BEFORE CLOSING!!!") Exit Case $cSave _GUIListViewEx_SaveListView($iLVIndex_1, "Save.lvs") GUICtrlSetState($cLoad, $GUI_ENABLE) Case $cLoad ; _GUIListViewEx_LoadListView($iLVIndex_2, "Save.lvs") ; But return now forced to 2D Case $cUp _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Up() Case $cDown _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Down() Case $cIns ; Insert row/col _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Insert("txt") Case $cCre ; MsgBox(0, "Dragging", "Test") _addToTable() Case $cDel ; Delete row/col _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Delete() Case $cHeaders $aRet = _GUIListViewEx_ReturnArray($iLVIndex_1, 4) _ArrayDisplay($aRet, "", Default, 8) EndSwitch $vRet = _GUIListViewEx_EventMonitor() 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) EndIf Case 2 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8) EndIf Case 3 MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF) Case 4 Local $aRet = StringSplit($vRet, ":") MsgBox($MB_SYSTEMMODAL, "Dragged", "From ListView " & $aRet[1] & @CRLF & "To ListView " & $aRet[2]) EndSwitch WEnd Func _addToTable() $Form1_1 = GUICreate("Add to Table", 389, 340, 253, 140) $Title = GUICtrlCreateLabel("Title", 16, 32, 24, 17) $Input1 = GUICtrlCreateInput("", 56, 32, 305, 21) $Image = GUICtrlCreateLabel("Image", 16, 72, 33, 17) $Input2 = GUICtrlCreateInput("", 56, 72, 305, 21) $Post = GUICtrlCreateLabel("Post", 16, 112, 25, 17) $Input3 = GUICtrlCreateInput("", 56, 112, 305, 70) $btnAddToTable = GUICtrlCreateButton("Add to Table", 216, 296, 137, 33) $btnCancel = GUICtrlCreateButton("Cancel", 40, 296, 145, 33) $Date = GUICtrlCreateLabel("Date", 16, 200, 27, 17) $idStart = GUICtrlCreateDate("2019/07/03 12:13:30", 56, 200, 305, 21) $stat = GUICtrlCreateLabel("Status", 16, 225, 25, 17) ; $iStat = GUICtrlCreateInput("", 56, 225, 305, 21) $iStat = GUICtrlCreateCombo("Closed", 56, 225, 305, 21) ; Add additional items to the combobox. GUICtrlSetData($iStat, "Active|Pending", "Active") ; $Input4 = GUICtrlCreateInput("", 56, 200, 305, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $btnCancel Exit Case $btnAddToTable ; add the values from the text field to the table EndSwitch WEnd EndFunc Any suggestions how to take the values and add them to my table? I appreciate your replies!
Nine Posted April 7, 2019 Posted April 7, 2019 There is multiple ways to achieve what you want. The easiest solution that I am thinking would be to pass a small array (by ref) to your function _addToTable (). Something like : Local $aTable[5] ; place that at the beginning of the script _addToTable ($aTable) ; is how you will call your function ; now $aTable contains the 5 fields of your _addToTable GUI Func _addToTable (ByRef $aField) ; is how your function will be declared Case $btnAddToTable $aField[0] = GUICtrlRead ($input1) $aField[1] = GUICtrlRead ($input2) $aField[2] = GUICtrlRead ($input3) $aField[3] = GUICtrlRead ($idStart) $aField[4] = GUICtrlRead ($iStat) Untested, just wrote it fast cause I got to go in a sec....but you will get the idea “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
FrancescoDiMuro Posted April 7, 2019 Posted April 7, 2019 Hi @algospider, and welcome to the AutoIt forums As @Nine suggested, you could use an array in which you store the fields' values, and then write them through _GUICtrlListView_AddArray(), for example. If you need further information, feel free to ask (providing an example of what you tried and what you are trying to accomplish) Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Moderators Melba23 Posted April 8, 2019 Moderators Posted April 8, 2019 (edited) algospider, This is how you do it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> #include <UpDownConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <Misc.au3> #include <String.au3> #include <Array.au3> #include "GUIListViewEx.au3" Global $sRet $hGUI = GUICreate("Task Table Helper", 750, 510) ; Create ListView GUICtrlCreateLabel("Task Table", 10, 10, 400, 20) $cLV_1 = GUICtrlCreateListView("#|Title|Image|Post|Schedule Date|Status", 10, 30, 720, 260, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetExtendedListViewStyle($cLV_1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP)) For $i = 0 To 3 _GUICtrlListView_SetColumnWidth($cLV_1, $i, 100) Next ; Create array and fill listview ;Global $aLVArray_1[8][6] ; You have no content at the start so you do not need an array <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Initiate ListView = sort on column click - editable headers - header colours - user colours $iLVIndex_1 = _GUIListViewEx_Init($cLV_1, "", 0, 0, True, 1 + 8 + 32) ; + 16 ; And you just use an empty string when intialising the ListView <<<<<<<<<< ; Set column edit status _GUIListViewEx_SetEditStatus($iLVIndex_1, 1) ; Default = standard text edit _GUIListViewEx_SetEditStatus($iLVIndex_1, 2, 2, "1|2|3", True) ; 2 = Read-only combo _GUIListViewEx_SetEditStatus($iLVIndex_1, 3, 3) ; 3 = DTP _GUIListViewEx_SetEditStatus($iLVIndex_1, 4) ; Default = standard text edit ; Create buttons for LH ListView GUICtrlCreateGroup("", 10, 300, 480, 160) GUICtrlCreateLabel("Up/Down", 25, 320, 80, 20, $SS_CENTER) $cUp = GUICtrlCreateButton("Up", 25, 340, 80, 30) $cDown = GUICtrlCreateButton("Down", 25, 380, 80, 30) GUICtrlCreateLabel("Row", 150, 320, 80, 20, $SS_CENTER) $cIns = GUICtrlCreateButton("Insert", 150, 340, 80, 30) $cDel = GUICtrlCreateButton("Delete", 150, 380, 80, 30) $cCre = GUICtrlCreateButton("Create", 150, 420, 80, 30) GUICtrlCreateLabel("Run/Stop", 275, 320, 80, 20, $SS_CENTER) $cRun = GUICtrlCreateButton("Run", 275, 340, 80, 30) $cStop = GUICtrlCreateButton("Stop", 275, 380, 80, 30) GUICtrlCreateLabel("Read", 400, 320, 80, 20, $SS_CENTER) $cContent = GUICtrlCreateButton("Content", 400, 340, 80, 30) $cHeaders = GUICtrlCreateButton("Headers", 400, 380, 80, 30) ; Create additional buttons $cSave = GUICtrlCreateButton("Save LH ListView", 10, 470, 150, 30) $cLoad = GUICtrlCreateButton("Load RH ListView", 180, 470, 150, 30) GUICtrlSetState($cLoad, $GUI_DISABLE) $cExit = GUICtrlCreateButton("Exit", 360, 470, 110, 30) ; If colours used then this function must be run BEFORE GUISetState _GUIListViewEx_MsgRegister() GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $cExit MsgBox(0, "Close", "SAVE BEFORE CLOSING!!!") Exit Case $cSave _GUIListViewEx_SaveListView($iLVIndex_1, "Save.lvs") GUICtrlSetState($cLoad, $GUI_ENABLE) Case $cLoad ; _GUIListViewEx_LoadListView($iLVIndex_2, "Save.lvs") ; But return now forced to 2D Case $cUp _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Up() Case $cDown _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Down() Case $cIns ; Insert row/col _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Insert("txt") Case $cCre ; MsgBox(0, "Dragging", "Test") _addToTable() Case $cDel ; Delete row/col _GUIListViewEx_SetActive($iLVIndex_1) _GUIListViewEx_Delete() Case $cHeaders $aRet = _GUIListViewEx_ReturnArray($iLVIndex_1, 4) _ArrayDisplay($aRet, "", Default, 8) EndSwitch $vRet = _GUIListViewEx_EventMonitor() 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) EndIf Case 2 If $vRet = "" Then MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF) Else _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8) EndIf Case 3 MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF) Case 4 Local $aRet = StringSplit($vRet, ":") MsgBox($MB_SYSTEMMODAL, "Dragged", "From ListView " & $aRet[1] & @CRLF & "To ListView " & $aRet[2]) EndSwitch WEnd Func _addToTable() $Form1_1 = GUICreate("Add to Table", 389, 340, 253, 140) $Title = GUICtrlCreateLabel("Title", 16, 32, 24, 17) $Input1 = GUICtrlCreateInput("", 56, 32, 305, 21) $Image = GUICtrlCreateLabel("Image", 16, 72, 33, 17) $Input2 = GUICtrlCreateInput("", 56, 72, 305, 21) $Post = GUICtrlCreateLabel("Post", 16, 112, 25, 17) $Input3 = GUICtrlCreateInput("", 56, 112, 305, 70) $btnAddToTable = GUICtrlCreateButton("Add to Table", 216, 296, 137, 33) $btnCancel = GUICtrlCreateButton("Cancel", 40, 296, 145, 33) $Date = GUICtrlCreateLabel("Date", 16, 200, 27, 17) $idStart = GUICtrlCreateDate("2019/07/03 12:13:30", 56, 200, 305, 21) $stat = GUICtrlCreateLabel("Status", 16, 225, 25, 17) ; $iStat = GUICtrlCreateInput("", 56, 225, 305, 21) $iStat = GUICtrlCreateCombo("Closed", 56, 225, 305, 21) ; Add additional items to the combobox. GUICtrlSetData($iStat, "Active|Pending", "Active") ; $Input4 = GUICtrlCreateInput("", 56, 200, 305, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $btnCancel ExitLoop Case $btnAddToTable ; add the values from the text field to the table ; Get the data into a delimited string <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sData = "#" & "|" & GUICtrlRead($Input1) & "|" & _ GUICtrlRead($Input2) & "|" & GUICtrlRead($Input3) & "|" & _ GUICtrlRead($idStart) &"|" & GUICtrlRead($iStat) ; And add it to the ListView <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< _GUIListViewEx_Insert($sData) ExitLoop EndSwitch WEnd GUIDelete($Form1_1) EndFunc With this UDF you MUST use the UDF functions to add/delete/modify the ListView content or it will not work. This is because the UDF uses a shadow array to reflect the ListView content and merely adding data to the ListView itself will mean the control and the array will no longer be synchronised leading to usually catastrophic results. M23 Edited April 10, 2019 by Melba23 29k 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
Skysnake Posted April 10, 2019 Posted April 10, 2019 Hi @algospider, @Melba23's code is probably a lot more sophisticated. But have a look at this? It's easy to follow and should give you an idea of what you can do. Skysnake Why is the snake in the sky?
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