Sign in to follow this  
Followers 0
Verssuss

Write data to file and load it after program start again

6 posts in this topic

#1 ·  Posted

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.

#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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Floops

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#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 by Verssuss

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Verssuss

Share this post


Link to post
Share on other sites

#6 ·  Posted

this is how i fixed Save/Load function
good job Verssuss xD

 

#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

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • david1337
      By david1337
      Hey guys
      I hope that I can get a little help with this one
       
      In this GUI example using GUIListViewEx, I have a list based on items found in test.txt.
      _____________________________________________
      item1
      item2
      item3
      ____________________________________________
      etc....
       
      When an item is selected, and I click the GetInfo button, a message will show the text of that item.
      Is it possible to activate a case like that as soon as the item is selected, so I don't need a button to start the case?
       
      #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $MainGUI_ManageItemList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_ManageItemList") Func MainGUI_ManageItemList() Local $Button1 $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1) $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30) $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) $GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageItemList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 MsgBox(0,"","Button 1 is pressed") Case $RemoveItem _GUIListViewEx_Delete() Case $GetInfo $ItemSelected = _GUICtrlListView_GetSelectedIndices($cLV, True) If IsArray($ItemSelected) And $ItemSelected[0] <> 0 Then ;This part makes sure it doesn't crash when no item is selected. $ItemSelectedText = _GUICtrlListView_GetItemText($cLV, $ItemSelected[1]) msgbox (0, "Selected item", $ItemSelectedText) EndIf EndSwitch WEnd EndFunc ;==>Main  
    • shotiko
      By shotiko
      I have a problem using listview and arrays: I try to create listview from file which contains multiples of 3 lines, therefore 3 columns and rows of total number of lines devided on 3. creation works fine but it adds extra rows as as number of items: ex. 24 lines in text creates 3 columns 8rows and other 16 rows empty. this is seen in listview and adds scroll even though my gui shouldn't need.  I tried looking at styles and extended styles but couldn't find forcing limitation on number of rows created.
      Func _config() $configMain = GUICreate('Settings', 530, 330, -1, -1, '', '', $mainGUI) Global $editBtn = GUICtrlCreateButton("Edit", 430, 50, 70, 30); Edit Btn Global $saveBtn = GUICtrlCreateButton("Save", 430, 120, 70, 30); Save Btn Global $cancelBtn = GUICtrlCreateButton("Cancel", 430, 180, 70, 30); Cancel Btn ; create listview with 3 columns $cLV = GUICtrlCreateListView("Server Name|server address|user Name", 10, 10, 400, 280) GUICtrlSetFont(-1, 10); set font for previous control _GUICtrlListView_SetColumnWidth(-1, 0, 95); first column size _GUICtrlListView_SetColumnWidth(-1, 1, 180); second column size _GUICtrlListView_SetColumnWidth(-1, 2, 100); third column size Local $j = 1, $k = 2, $l = 3 ; starting lines for $j - server; $k - server address; $l - account name For $i = 1 To _FileCountLines($configF); 1 to number of lines present in file $sLine = FileReadLine($configF, $j); Server name Line read $saLine = FileReadLine($configF, $k); server address Line read $anLine = FileReadLine($configF, $l); user Name read $listV = GUICtrlCreateListViewItem($sLine & '|' & $saLine & '|' & $anLine, $cLV); assign 3 values each with iteration _ ; seperated and concatenated by '|' $j += 3; move three lines below $k += 3; move three lines below $l += 3; move three lines below Next $cLVarray = _GUIListViewEx_ReadToArray($cLV); read ListView to array $cLVinit = _GUIListViewEx_Init($cLV, $cLVarray, 0, 0, True, 1 + 2 + 512); Initialize _GUIListViewEx_SetEditStatus($cLVinit, "*") ; all columns can be edited _GUIListViewEx_MsgRegister() ; receive messages for UDF functions _GUIListViewEx_SetActive($cLVinit) ; set $cLVinit - 1 as active GUISetState(@SW_SHOW, $configMain) EndFunc ;==>_config  
      i can avoid this by
      For $i = 1 To 50 _GUICtrlListView_DeleteItem($cLV, 8) $i += 1 Next
      if i know maximum number of rows i will need, but items in listview are editable and therefore unreliable. I tried
      _GUICtrlListView_DeleteItem($cLV, _GUICtrlListView_GetItemCount($cLV) / _GUICtrlListView_GetColumnCount($cLV))
      this returns empty listview
      when it comes to editing part:
      $cLVarrayModif = _GUIListViewEx_ReturnArray($cLVinit, 0)
                       _ArrayDisplay($cLVarrayModif)
      this also shows 24 rows 3columns
    • marcoauto
      By marcoauto
      Ciao,
      I'm trying to filter a draggable Listview using checkbox, but when I filter a listview (idListiview) and I drag and drop a record to another listview, the listview that i filtered returns not filtered and the record that i would drag and drop is not the correct one
      There are 4 listview, LISTVIEWL1, LISTVIEWL2, LISTVIEWL3 and LISTVIEW. The filter must be work for LISTVIEW (and they work)
      Where I wrong?
      This is my script (Is not complete, but I rewrite it for the forum)
      I know that is not an optimized script...
       
      Thanks and sorry for my bad english
       
      Marco
       
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> #include <EditConstants.au3> #include "GUIListViewEx.au3" #include <ButtonConstants.au3> #include <StaticConstants.au3> #include "_FileListToArrayEx_Marco.au3" #include <Array.au3> ; ******************************************************************************************************* ; **************************** LETTURA FILE CODICI DALLE CARTELLE *************************************** ; ******************************************************************************************************* ;~ $listaTotaleCodici = _FileListToArrayEx ("images", "*.png", 4);1+4); 1+4+128) ;<== original dim $listaTotaleCodici[11] $listaTotaleCodici[0] = 10 $listaTotaleCodici[1] = "01A_COD1_Tipo1_CHECK2_01_123456789_02_.png" $listaTotaleCodici[2] = "01A_COD2_Tipo1_CHECK3_02_321456789_01_.png" $listaTotaleCodici[3] = "02A_COD1_Tipo1_CHECK2_01_231456798_02_.png" $listaTotaleCodici[4] = "03A_COD1_Tipo2_CHECK1_01_888456789_01_.png" $listaTotaleCodici[5] = "04A_COD2_Tipo2_CHECK1_01_111456789_02_.png" $listaTotaleCodici[6] = "05A_COD1_Tipo1_CHECK2_01_777456789_02_.png" $listaTotaleCodici[7] = "05A_COD1_Tipo3_CHECK1_01_666456789_01_.png" $listaTotaleCodici[8] = "06A_COD1_Tipo1_CHECK2_01_555456789_02_.png" $listaTotaleCodici[9] = "07A_COD1_Tipo3_CHECK2_01_444456789_01_.png" $listaTotaleCodici[10] = "08A_COD1_Tipo1_CHECK2_01_666777789_02_.png" ;~ $listaTotaleCodici[11] = "08A_COD2_Tipo1_CHECK3_01_222456789_02_.png" ; read some png files ; Ex: ; 01A_COD_Tipo1_CHECK2_N_NUMBER_XY.png ; 02A_COD_Tipo1_CHECK2_N_NUMBER_XY.png ; 03A_COD_Tipo3_CHECK1_N_NUMBER_XY.png ; where NUMBER is differentfor any png files ; COD has max 2 values (COD1 or COD2) ; Tipo has max 3 values ; ******************************************************************************************************* ; ********************************* DICHIARAZIONI VARIABILI ********************************************* ; ******************************************************************************************************* dim $aArray[8] dim $filtrare[13] ;array dove vengono memorizzate le parole da filtrare (899, 01, webcom, ecc ecc) Global $fatto = 0 Global $iLV_L1,$iLV_L2,$iLV_L3,$iLV_Codici Dim $idItem[800] Dim $idItemL1[3] Dim $idItemL2[3] Dim $idItemL3[3] Global $idListviewL1, $idListviewL2, $idListviewL3, $idListview $x = 120 $y = 96 $offsetxpreview = 24+100 $offsetypreview = 129+96 $offsetx = $offsetxpreview + $x + 24 $offsety = 12 Global $offsetxradio = 345 Global $aList1, $tmp_String Dim $TotaleCodici[800] Dim $aTempArray[800] Dim $idButton[6] Global $offsetxbutton = 20 Global $offsetybutton = 45 Global $idx=0 Global $b = 0 Global $filtrato = 0 ; ******************************************************************************************************* ; **************************************** PARTENZA GDI ************************************************* ; ******************************************************************************************************* _GDIPlus_Startup() ;~ GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; ******************************************************************************************************* ; *********************************** CREAZIONE GUI PRINCIPALE ****************************************** ; ******************************************************************************************************* $g_hGUI = GUICreate("GUI", 1038, 700, 192, 124) GUISetState() Global $Graphic = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ; ******************************************************************************************************* ; **************************************** CREAZIONE CHECKBOX ****************************************** ; ******************************************************************************************************* GUIStartGroup() $RadioCodice1 = GUICtrlCreateCheckbox("CHECK1", $offsetxradio+112, 10, 100, 17) GUICtrlSetState($RadioCodice1, $GUI_CHECKED) $RadioCodice2 = GUICtrlCreateCheckbox("CHECK2", $offsetxradio+227, 10, 100, 17) GUICtrlSetState($RadioCodice2, $GUI_CHECKED) $RadioCodice3 = GUICtrlCreateCheckbox("CHECK3", $offsetxradio+341, 10, 100, 17) GUICtrlSetState($RadioCodice3, $GUI_CHECKED) $Label1 = GUICtrlCreateLabel("LABEL:", $offsetxradio + 24 + 35, 10+2, 50, 17) $RadioTipo1 = GUICtrlCreateCheckbox("Tipo1", $offsetxradio+112, 45, 100, 17) GUICtrlSetState($RadioTipo1, $GUI_CHECKED) $RadioTipo2 = GUICtrlCreateCheckbox("Tipo2", $offsetxradio+227, 45, 100, 17) GUICtrlSetState($RadioTipo2, $GUI_CHECKED) $RadioTipo3 = GUICtrlCreateCheckbox("Tipo3", $offsetxradio+341, 45, 100, 17) GUICtrlSetState($RadioTipo3, $GUI_CHECKED) $LabelTipo = GUICtrlCreateLabel("TIPO:", $offsetxradio + 24 + 35, 45+2, 50, 17) Global $offsetxradio = 345 ;~ GUIStartGroup() $Radio1 = GUICtrlCreateCheckbox("A", $offsetxradio+112, 80, 50, 17) ;~ Local $idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 10, 10, 185, 25) GUICtrlSetState($Radio1, $GUI_CHECKED) $Radio2 = GUICtrlCreateCheckbox("B", $offsetxradio+169, 80, 50, 17) GUICtrlSetState($Radio2, $GUI_CHECKED) $Radio3 = GUICtrlCreateCheckbox("C", $offsetxradio+227, 80, 50, 17) GUICtrlSetState($Radio3, $GUI_CHECKED) $Radio4 = GUICtrlCreateCheckbox("D", $offsetxradio+284, 80, 50, 17) GUICtrlSetState($Radio4, $GUI_CHECKED) $Radio5 = GUICtrlCreateCheckbox("E", $offsetxradio+341, 80, 50, 17) GUICtrlSetState($Radio5, $GUI_CHECKED) $Radio6 = GUICtrlCreateCheckbox("F", $offsetxradio+399, 80, 50, 17) GUICtrlSetState($Radio6, $GUI_CHECKED) $Radio7 = GUICtrlCreateCheckbox("ALL", $offsetxradio+456, 80, 50, 17) GUICtrlSetState($Radio7, $GUI_CHECKED) $LabelGruppi = GUICtrlCreateLabel("LABEL:", $offsetxradio + 24 + 35, 80+2, 50, 17) $ButtonFiltra = GUICtrlCreateButton("Filter", 870, 12, 150, 84) ;~ GUICtrlSetBkColor(-1,0x00FF00 $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Graphic) $hPen = _GDIPlus_PenCreate(0xff000000, 2);red, 3pixels wide ; ******************************************************************************************************* ; **************************************** CREAZIONE BOTTONI ******************************************* ; ******************************************************************************************************* $cDelete_Button = GUICtrlCreateButton("Delete Line", 870, 115, 150, 30) $idListviewL1 = GUICtrlCreateListView("LISTVIEWL1", 400, 6+96, 450, 96) _GUICtrlListView_SetColumnWidth($idListviewL1, 0, 446) $idListviewL2 = GUICtrlCreateListView("LISTVIEWL2", 400, 6+96+96, 450, 96) _GUICtrlListView_SetColumnWidth($idListviewL2, 0, 446) $idListviewL3 = GUICtrlCreateListView("LISTVIEWL3", 400, 6+96+96+96, 450, 96) _GUICtrlListView_SetColumnWidth($idListviewL3, 0, 446) $idListview = GUICtrlCreateListView("LISTVIEW", 400, 6+96+96+96+96, 450, 573-96-96-96) _GUICtrlListView_SetColumnWidth($idListview, 0, 446) if $fatto = 0 Then ConsoleWrite("fatto = 0" & @CRLF) For $i = 1 To $listaTotaleCodici[0] ; Loop through the array to display the individual values. local $aArray = StringSplit($listaTotaleCodici[$i], '_');, $STR_ENTIRESPLIT) ; Pass the variable to StringSplit and using the delimiter "\n". Local $aList[$listaTotaleCodici[0]+1], $sText If IsArray($aArray) Then $sText = $aArray[1] & " " & $aArray[2] & " " & $aArray[3] & " " & $aArray[4] & " " & $aArray[6] $aList[$i] = $sText GUICtrlCreateListViewItem($sText, $idListview) EndIf Next $iLV_Codici = _GUIListViewEx_Init($idListview, $aList, 0, 0, True, 128 + 256) $TotaleEtichetteCodici = _GUIListViewEx_ReadToArray($idListview) $fatto = 1 EndIf $iLV_L1 = _GUIListViewEx_Init($idListviewL1, $idItemL1, 0, 0, True) ; No external drop, will drag to others - items deleted on drag $iLV_L2 = _GUIListViewEx_Init($idListviewL2, $idItemL2, 0, 0, True) ; No external drop, will drag to others - items deleted on drag $iLV_L3 = _GUIListViewEx_Init($idListviewL3, $idItemL3, 0, 0, True) ; No external drop, will drag to others - items deleted on drag ;~ $iLV_Codici = _GUIListViewEx_Init($idListview, $idItem, 0, 0, True, 128 + 256) ; No external drop, will drag to others - items NOT deleted on drag ;~ GUISetState() _GUIListViewEx_MsgRegister() _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, 1, 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; ******************************************************************************************************* ; ********************************************* MAIN LOOP *********************************************** ; ******************************************************************************************************* Global $idMsg ;~ ; Loop until the user exits. While 1 Sleep(10) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cDelete_Button $listaTotaleCodiciaAttiva = _GUIListViewEx_GetActive() ConsoleWrite(" active = " & $listaTotaleCodiciaAttiva & @CRLF) if $listaTotaleCodiciaAttiva <> 1 Then _GUIListViewEx_Delete() EndIf Case $ButtonFiltra _filtraCodici() EndSwitch WEnd ; Clean up resources _GDIPlus_GraphicsDispose($Graphic) _GDIPlus_Shutdown() ; ******************************************************************************************************* ; ***************************************** QUIT FUNCTION *********************************************** ; ******************************************************************************************************* Func Quit() _GDIPlus_Shutdown() Exit EndFunc ; ******************************************************************************************************* ; **************************************** ISCHECKED FUNCTION ******************************************* ; ******************************************************************************************************* Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked ; ******************************************************************************************************* ; ************************************ WM_NOTIFY FUNCTION *********************************************** ; ******************************************************************************************************* Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) _GUIListViewEx_WM_NOTIFY_Handler($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $index $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) $hWndFrom = DllStructGetData($tStruct, 1) $idFrom = DllStructGetData($tStruct, 2) $code = DllStructGetData($tStruct, 3) $index = DllStructGetData($tStruct, 4) $hWndListView1 = GUICtrlGetHandle($iLV_L1) ;($idListviewL1) $hWndListView2 = GUICtrlGetHandle($iLV_L2) ;($idListviewL2) $hWndListView3 = GUICtrlGetHandle($iLV_L3) ;($idListviewL3) $hWndListViewCodici = GUICtrlGetHandle($iLV_Codici) ;($idListview) Switch $code Case $NM_CLICK ;Left Mouse Button ConsoleWrite("left mouse button") Switch $idFrom Case $iLV_L1 $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ ConsoleWrite("+Click: " & $index & @CRLF) $text = _GUICtrlListView_GetItemText($iLV_L1, DllStructGetData($tInfo, "Index")) ConsoleWrite("+text: " & $text & @CRLF) EndSwitch Case $NM_DBLCLK ;Double Left Mouse Button Switch $idFrom Case $idListviewL1 $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ ConsoleWrite("+Click: " & $index & @CRLF) $text = _GUICtrlListView_GetItemText($idListviewL1, DllStructGetData($tInfo, "Index")) ConsoleWrite("+textDBClick: " & $text & @CRLF) Case $idListview $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ ConsoleWrite("+Click: " & $index & @CRLF) $text = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index")) ConsoleWrite("+textDBClick: " & $text & @CRLF) EndSwitch Case $GUI_EVENT_CLOSE Quit() EndSwitch EndFunc ;==>WM_NOTIFY ; ******************************************************************************************************* ; ***************************************** FILTRA CODICI *********************************************** ; ******************************************************************************************************* Func _filtraCodici() $aTempArray = $TotaleEtichetteCodici ;$listaTotaleCodici Local $filtrato = 0 If _IsChecked($Radio1) Then $filtrare[1] = 1 Else $filtrare[1] = "A" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[1]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($Radio2) Then $filtrare[2] = 1 Else $filtrare[2] = "B" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[2]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($Radio3) Then $filtrare[3] = 1 Else $filtrare[3] = "C" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[3]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($Radio4) Then $filtrare[4] = 1 Else $filtrare[4] = "D" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[4]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($Radio5) Then $filtrare[5] = 1 Else $filtrare[5] = "E" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[5]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($Radio6) Then $filtrare[6] = 1 Else $filtrare[6] = "F" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = StringLeft($aTempArray[$b][0],3) If StringInStr($tmp_String,$filtrare[6]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioTipo1) Then $filtrare[7] = 1 Else $filtrare[7] = "Tipo1" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = $aTempArray[$b][0] If StringInStr($tmp_String,$filtrare[7]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioTipo2) Then $filtrare[8] = 1 Else $filtrare[8] = "Tipo2" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 $tmp_String = $aTempArray[$b][0] If StringInStr($tmp_String,$filtrare[8]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioTipo3) Then $filtrare[9] = 1 Else $filtrare[9] = "Tipo3" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 $tmp_String = $aTempArray[$b][0] If StringInStr($tmp_String,$filtrare[9]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioCodice1) Then $filtrare[10] = 1 Else $filtrare[10] = "CHECK1" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = $aTempArray[$b][0] If StringInStr($tmp_String,$filtrare[10]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioCodice2) Then $filtrare[11] = 1 Else $filtrare[11] = "CHECK2" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = $aTempArray[$b][0] ;~ ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF) If StringInStr($tmp_String,$filtrare[11]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf If _IsChecked($RadioCodice3) Then $filtrare[12] = 1 Else $filtrare[12] = "CHECK3" $filtrato = 1 For $b=UBound($aTempArray) -1 to 0 step -1 Global $tmp_String = $aTempArray[$b][0] ;~ ConsoleWrite(@CRLF & "$tmp_Stringgg= " & $tmp_String & @CRLF) If StringInStr($tmp_String,$filtrare[12]) Then _ArrayDelete($aTempArray, $b) EndIf Next EndIf _ArrayDisplay($aTempArray,"fine ciclo") _GUICtrlListView_DeleteAllItems($idListview) ;~ $iLV_Codici = _GUIListViewEx_Close($idListview) ConsoleWrite("_GUICtrlListView_DeleteAllItems" & @CRLF) IF $filtrato = 0 Then For $a=0 to UBound($TotaleEtichetteCodici)-1 ; Loop through the array to display the individual values. Local $aList1[UBound($TotaleEtichetteCodici)], $sText If IsArray($TotaleEtichetteCodici) Then $sText = $TotaleEtichetteCodici[$a][0] ConsoleWrite("sText non filtrato = " & $sText & @CRLF) $aList1[$a] = $sText GUICtrlCreateListViewItem($sText, $idListview) EndIf Next EndIf if $filtrato = 1 Then For $a=0 to UBound($aTempArray)-1 ; Loop through the array to display the individual values. Global $aList1[UBound($aTempArray)], $sText If IsArray($aTempArray) Then $sText = $aTempArray[$a][0] ConsoleWrite("sText = " & $sText & @CRLF) $aList1[$a] = $sText GUICtrlCreateListViewItem($sText, $idListview) EndIf Next EndIf $iLV_Codici = _GUIListViewEx_Close($idListview) $iLV_Codici = _GUIListViewEx_Init($idListview, $aList1, 0, 0, True, 128 + 256); 0, 0, True, 1 + 2 + 8, "0;2") EndFunc ;==>_filtraCodici
    • Kovacic
      By Kovacic
      Greetings, I cant post my code because its over 2000 lines and has mixed SQL queries that will give away too much company data, so I will juts post an example of GUIListViewEx:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $listview, $button, $item1, $item2, $item3, $item4, $msg GUICreate("Drop in Listview", 220, 200, 100, 100, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("col1|col2 ", 10, 10, 200, 150) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $item1 = GUICtrlCreateListViewItem("1|4", $listview) $item2 = GUICtrlCreateListViewItem("2|5", $listview) $item3 = GUICtrlCreateListViewItem("3|6", $listview) GUISetState() Do $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_DROPPED GUICtrlCreateListViewItem(@GUI_DRAGFILE&'|', $listview) EndSelect Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Is it possible to easily empty the list with one simple button or function? I looked around the UDF and could not find anything but a single line delete.
      Thanks in advance!