Verssuss Posted May 10, 2017 Share Posted May 10, 2017 hello guys i have some problems. i never do it before but i need: 1. simply way to save data from ListView to file and load it by button $button_load after i run program again. plz show me function 2. is this possible to make button copy ? (selected items) 3. is here way to add checkbox on each item ?? here is my simple code. expandcollapse popup#AutoIt3Wrapper_UseX64=Y #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #include <GUIConstants.au3> #include <ButtonConstants.au3> #include <SendMessage.au3> #include <GuiEdit.au3> #include <EditConstants.au3> $GUI = GUICreate("Story", 500, 400,200,200) GUISetState() $ListView = GUICtrlCreateListView("Name|ITEM|DMG|SPEED|PRICE", 10, 10, 300, 300, $LVS_SHOWSELALWAYS) $iLV_Index = _GUIListViewEx_Init($ListView, "", 0, 0, True, 1 + 2 + 8) _GUICtrlListView_SetExtendedListViewStyle($ListView, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES) $button_items = GUICtrlCreateButton("ADD ITEM", 350, 5, 90, 25) $button_random = GUICtrlCreateButton("ADD RANDOM", 350, 35, 90, 25) $button_up = GUICtrlCreateButton("UP", 350, 100, 50, 25) $button_down = GUICtrlCreateButton("DOWN", 350, 140, 50, 25) $button_copy = GUICtrlCreateButton("COPY", 350, 180, 50, 25) ; This is even possible tomake it work ?? $button_del_selected = GUICtrlCreateButton("DEL", 350, 220, 50, 25) $button_load = GUICtrlCreateButton("Load", 350, 300, 33, 30) $button_exit = GUICtrlCreateButton("Exit", 350, 330, 33, 30) Global $iCount = 0, $vData, $iEditMode = 0 _GUIListViewEx_MsgRegister() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button_exit Exit Case $button_load _load() Case $button_random Global $vData[] = ["Name" & $iCount, "Sword", "450", "5", "3000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Axe", "700", "2", "4500$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Bow", "300", "7", "2000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Magic", "1000", "1", "6000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Case $button_items gui2() GUICtrlSetState($GUI, $GUI_DISABLE) Case $button_del_selected _GUIListViewEx_Delete() Case $button_up _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Up() Case $button_down _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Down() EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) WEnd Func gui2() $pos_GUI2 = WinGetPos($GUI) Local $GUI2 = GUICreate("Items", 300, 300, $pos_GUI2[0]+200, $pos_GUI2[1]+100,-1, $WS_EX_TOPMOST) Local $i1 = GUICtrlCreateInput("", 50, 30, 200, 25) Local $i2 = GUICtrlCreateInput("", 50, 60, 200, 25) Local $i3 = GUICtrlCreateInput("", 50, 90, 200, 25) Local $i4 = GUICtrlCreateInput("", 50, 120, 200, 25) Local $GUI2_button2 = GUICtrlCreateButton("ANULUJ", 80, 200, 50, 30) Local $GUI2_button1 = GUICtrlCreateButton("OK", 170, 200, 50, 30) Local $GUI2_label = GUICtrlCreateLabel("Write stats", 10, 5) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $GUI2_button2 GUIDelete($GUI2) GUICtrlSetState($GUI, $GUI_ENABLE) ExitLoop Case $GUI2_button1 Global $vData[] = ["Name" & $iCount, GUICtrlRead($i1), GUICtrlRead($i2), GUICtrlRead($i3), GUICtrlRead($i4)] $iCount += 1 _GUIListViewEx_Insert($vData) GUIDelete($GUI2) ExitLoop GUICtrlSetState($GUI, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>gui2 Func _quit() Exit EndFunc ;==>_quit Func _load() EndFunc ;==>_quit thanks u Link to comment Share on other sites More sharing options...
Floops Posted May 10, 2017 Share Posted May 10, 2017 (edited) 1. Below is a function I used to save a ListView to an Array, you can try if it works properly for you. If so you can use _FileWriteFromArray to save it to a file. Afterwards you can use _FileReadToArray to load it back into an Array and add it into the ListView using _GUICtrlListView_AddArray. That is how I handled situations like this, maybe there are better solutions. $aListView = _lv_to_array($ListView) _ArrayDisplay($aListView) Func _lv_to_array($hListView) Local $aReturn[_GUICtrlListView_GetItemCount($hListView)][_GUICtrlListView_GetColumnCount($hListView)] For $i = 0 To _GUICtrlListView_GetItemCount($hListView) - 1 For $j = 0 To _GUICtrlListView_GetColumnCount($hListView) - 1 $aReturn[$i][$j] = _GUICtrlListView_GetItemText($hListView, $i, $j) Next Next Return $aReturn EndFunc 2. No clue, sorry. 3. You can try the extended style $LVS_EX_CHECKBOXES. Haven't used that one before so I can't say much about it though. Edited May 10, 2017 by Floops Link to comment Share on other sites More sharing options...
232showtime Posted May 10, 2017 Share Posted May 10, 2017 (edited) 2 hours ago, Verssuss said: 1. simply way to save data from ListView to file and load it by button $button_load after i run program again. plz show me function better solution is to use @Melba23 GUIListViewEx.au3 just use the search option. didnt notice your include, use _GUIListViewEx_SaveListView($yourlistview, "Save.lvs") and _GUIListViewEx_LoadListView($yourlistview, "Save.lvs") func. Edited May 10, 2017 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
Verssuss Posted May 10, 2017 Author Share Posted May 10, 2017 (edited) expandcollapse popup#AutoIt3Wrapper_UseX64=Y #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #include <GUIConstants.au3> #include <ButtonConstants.au3> #include <SendMessage.au3> #include <GuiEdit.au3> #include <EditConstants.au3> $GUI = GUICreate("Story", 500, 400,200,200) GUISetState() $ListView = GUICtrlCreateListView("Name|ITEM|DMG|SPEED|PRICE", 10, 10, 300, 300, $LVS_SHOWSELALWAYS) $iLV_Index = _GUIListViewEx_Init($ListView, "", 0, 0, True, 1 + 2 + 8) _GUICtrlListView_SetExtendedListViewStyle($ListView, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES) $button_items = GUICtrlCreateButton("ADD ITEM", 350, 5, 90, 25) $button_random = GUICtrlCreateButton("ADD RANDOM", 350, 35, 90, 25) $button_up = GUICtrlCreateButton("UP", 350, 100, 50, 25) $button_down = GUICtrlCreateButton("DOWN", 350, 140, 50, 25) $button_copy = GUICtrlCreateButton("COPY", 350, 180, 50, 25) ; This is even possible tomake it work ?? $button_del_selected = GUICtrlCreateButton("DEL", 350, 220, 50, 25) $button_save = GUICtrlCreateButton("Save", 350, 300, 33, 30) $button_load = GUICtrlCreateButton("Load", 350, 330, 33, 30) $button_exit = GUICtrlCreateButton("Exit", 350, 360, 33, 30) Global $iCount = 0, $vData, $iEditMode = 0 _GUIListViewEx_MsgRegister() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button_exit Exit Case $button_save _save() Case $button_load _load() Case $button_random Global $vData[] = ["Name" & $iCount, "Sword", "450", "5", "3000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Axe", "700", "2", "4500$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Bow", "300", "7", "2000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Global $vData[] = ["Name" & $iCount, "Magic", "1000", "1", "6000$"] $iCount += 1 _GUIListViewEx_Insert($vData) Case $button_items gui2() GUICtrlSetState($GUI, $GUI_DISABLE) Case $button_del_selected _GUIListViewEx_Delete() Case $button_up _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Up() Case $button_down _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Down() EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) WEnd Func gui2() $pos_GUI2 = WinGetPos($GUI) Local $GUI2 = GUICreate("Items", 300, 300, $pos_GUI2[0]+200, $pos_GUI2[1]+100,-1, $WS_EX_TOPMOST) Local $i1 = GUICtrlCreateInput("", 50, 30, 200, 25) Local $i2 = GUICtrlCreateInput("", 50, 60, 200, 25) Local $i3 = GUICtrlCreateInput("", 50, 90, 200, 25) Local $i4 = GUICtrlCreateInput("", 50, 120, 200, 25) Local $GUI2_button2 = GUICtrlCreateButton("ANULUJ", 80, 200, 50, 30) Local $GUI2_button1 = GUICtrlCreateButton("OK", 170, 200, 50, 30) Local $GUI2_label = GUICtrlCreateLabel("Write stats", 10, 5) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $GUI2_button2 GUIDelete($GUI2) GUICtrlSetState($GUI, $GUI_ENABLE) ExitLoop Case $GUI2_button1 Global $vData[] = ["Name" & $iCount, GUICtrlRead($i1), GUICtrlRead($i2), GUICtrlRead($i3), GUICtrlRead($i4)] $iCount += 1 _GUIListViewEx_Insert($vData) GUIDelete($GUI2) ExitLoop GUICtrlSetState($GUI, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>gui2 Func _quit() Exit EndFunc ;==>_quit Func _save() _GUIListViewEx_SaveListView($ListView, "Save.lvs") Beep(500) EndFunc Func _load() _GUIListViewEx_LoadListView($ListView, "Save.lvs") Beep(400) EndFunc;==>_quit not any work ;/ also there in no any exemple with used _GUIListViewEx_SaveListView Edited May 10, 2017 by Verssuss Link to comment Share on other sites More sharing options...
Verssuss Posted May 10, 2017 Author Share Posted May 10, 2017 (edited) 16 hours ago, Floops said: 3. You can try the extended style $LVS_EX_CHECKBOXES. Haven't used that one before so I can't say much about it though. thx Floops already works fine i just add this Local $iStylesEx = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES), $idListview $ListView = GUICtrlCreateListView("Name|ITEM|DMG|SPEED|PRICE", 10, 10, 300, 300, $LVS_SHOWSELALWAYS) $iLV_Index = _GUIListViewEx_Init($ListView, "", 0, 0, True, 1 + 2 + 8) _GUICtrlListView_SetExtendedListViewStyle($ListView, $iStylesEx) ok guys. problem #1 and #3 already fixed. now working just on copy button but i think there will be no problems with that after i got save / open get to work Edited May 10, 2017 by Verssuss Link to comment Share on other sites More sharing options...
Verssuss Posted May 11, 2017 Author Share Posted May 11, 2017 this is how i fixed Save/Load function good job Verssuss xD expandcollapse popup#AutoIt3Wrapper_UseX64=Y #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #include <GUIConstants.au3> #include <ButtonConstants.au3> #include <SendMessage.au3> #include <GuiEdit.au3> #include <EditConstants.au3> $GUI = GUICreate("Story", 500, 400,200,200) GUISetState() $ListView = GUICtrlCreateListView("Name|ITEM|DMG|SPEED|PRICE", 10, 10, 300, 300, $LVS_SHOWSELALWAYS) $iLV_Index = _GUIListViewEx_Init($ListView, "", 0, 0, True, 1 + 2 + 8) _GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) $button_items = GUICtrlCreateButton("ADD ITEM", 350, 5, 90, 25) $button_random = GUICtrlCreateButton("ADD RANDOM", 350, 35, 90, 25) $button_up = GUICtrlCreateButton("UP", 350, 100, 50, 25) $button_down = GUICtrlCreateButton("DOWN", 350, 140, 50, 25) $button_copy = GUICtrlCreateButton("COPY", 350, 180, 50, 25) ; This is even possible tomake it work ?? $button_del_selected = GUICtrlCreateButton("DEL", 350, 220, 50, 25) $button_save = GUICtrlCreateButton("Save", 350, 300, 33, 30) $button_load = GUICtrlCreateButton("Load", 350, 330, 33, 30) $button_exit = GUICtrlCreateButton("Exit", 350, 360, 33, 30) Global $iCount = 0, $vData, $iEditMode = 0 _GUIListViewEx_MsgRegister() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button_exit Exit Case $button_save _save() Case $button_load _load() Case $button_items gui2() GUICtrlSetState($GUI, $GUI_DISABLE) Case $button_del_selected _GUIListViewEx_Delete() Case $button_up _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Up() Case $button_down _GUIListViewEx_SetActive($iLV_Index) _GUIListViewEx_Down() EndSwitch $vRet = _GUIListViewEx_EventMonitor($iEditMode) WEnd Func gui2() $pos_GUI2 = WinGetPos($GUI) Local $GUI2 = GUICreate("Items", 300, 300, $pos_GUI2[0]+200, $pos_GUI2[1]+100,-1, $WS_EX_TOPMOST,$GUI) Local $inp1 = GUICtrlCreateInput("", 50, 30, 200, 25) Local $inp2 = GUICtrlCreateInput("", 50, 60, 200, 25) Local $inp3 = GUICtrlCreateInput("", 50, 90, 200, 25) Local $inp4 = GUICtrlCreateInput("", 50, 120, 200, 25) Local $button_anuluj = GUICtrlCreateButton("ANULUJ", 80, 200, 50, 30) Local $button_ok = GUICtrlCreateButton("OK", 170, 200, 50, 30) Local $label = GUICtrlCreateLabel("Write stats", 10, 5) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button_anuluj GUIDelete($GUI2) GUICtrlSetState($GUI, $GUI_ENABLE) ExitLoop Case $button_ok Global $vData[] = ["Name" & $iCount, GUICtrlRead($inp1), GUICtrlRead($inp2), GUICtrlRead($inp3), GUICtrlRead($inp4)] $iCount += 1 _GUIListViewEx_Insert($vData) GUIDelete($GUI2) ExitLoop GUICtrlSetState($GUI, $GUI_ENABLE) EndSwitch WEnd EndFunc ;==>gui2 Func _save() $file_save = FileSaveDialog("Choose a filename.", "", "Data (*.lvs)", $FD_PATHMUSTEXIST) _GUIListViewEx_SaveListView($iLV_Index, $file_save) EndFunc Func _load() Local $file_open = FileOpenDialog("Choose Scheme", @ScriptDir & "\", "Data (*.lvs)", $FD_FILEMUSTEXIST) _GUIListViewEx_LoadListView($iLV_Index, $file_open) EndFunc Func _quit() Exit EndFunc ;==>_quit 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