Jump to content

GUIListViewEx.au3 | Clear the entire list with one button?


Kovacic
 Share

Go to solution Solved by Melba23,

Recommended Posts

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!

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Use GUICtrlDelete to delete and then recreate the Control.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The other issues is, with GUIListViewEx, if you have more than one list, they are numbered so you can activate them by index number depending on where you need to manipulate data, I will give it a try, but I'm afraid it will mess with my index numbers... 

Example:

Current lists:

Bulk hardware tab: list 1

Search results tab: list 2

if I delete and recreate list 1, will in come back as list 3?

I am thinking the delete line by line might be the best idea.

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

  • Moderators

Kovacic,

I wrote the UDF so I hope I will be able to give you an answer, but it is pretty late here so I will look into it tomorrow. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi. Use:

_GUICtrlListView_DeleteAllItems ($listview)

 

Edit:

as water and JohnOne say, it would be faster than I'm say.

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Does _GUICtrlListView_DeleteAllItems do it for you?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Does _GUICtrlListView_DeleteAllItems do it for you?

I did try this but it didn't seem to clear anything.

 

Kovacic,

I wrote the UDF so I hope I will be able to give you an answer, but it is pretty late here so I will look into it tomorrow. :)

M23

 

Thanks! Much appreciated!! :D

Edited by Kovacic

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

You should post an example of your listview using the actual GUIListViewEx functions, and how you attempted to delete the listview items. Currently you have a script posted that shows neither of these things.

 

EDIT: I just tested the _GUICtrlListView_DeleteAllItems function on one of the examples posted in the GUIListViewEx thread, and it worked flawlessly.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators
  • Solution

Kovacic,

As I suspected it is not difficult to do. You need get the UDF to stop tracking the ListView in question with _GUIListViewEx_Close, empty it using the already suggested _GUICtrlListView_DeleteAllItems, and then re-initialise the ListView with _GUIListViewEx_Init using an empty array. :)

There is no problem with the index. Firstly, the UDF looks for the first blank element in the list, so the chances are that it will be the one you just closed and so it will use that and actually return the same index. Secondly, if you store the index in a variable then you can just reassign the new index to that variable and it really does not matter at all what the actual value is - I hope you were not hard coding it! :o

Here is an example script with 2 buttons which empty the 2 ListViews. Look for the <<<<<<<<<< section to see the code used:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIListViewEx.au3"

#include <Array.au3> ; Just for display in example

Opt("GUICloseOnESC", 0)

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" & @CRLF & "Multiple selection - no count - sort && editable (0 && 2)", 10, 5, 300, 30)

$cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)
; 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 - sort & editable - only cols 0 & 2 (plus headers) editable
$iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 0, 0, True, 1 + 2 + 8, "0;2")

; Create Right ListView
GUICtrlCreateLabel("UDF ListView" & @CRLF & "Single sel - count element - editable (all)", 430, 5, 300, 30)

$hListView_Right = _GUICtrlListView_Create($hGUI, "", 430, 40, 200, 300, BitOR($LVS_DEFAULT, $WS_BORDER))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_AddColumn($hListView_Right, "Peter", 83)
_GUICtrlListView_AddColumn($hListView_Right, "Paul", 83)
_GUICtrlListView_AddColumn($hListView_Right, "Mary", 83)

_GUICtrlListView_SetTextBkColor($hListView_Right, 0xDDFFDD)

; Fill Right ListView
For $i = 1 To $iCount_Right
    _GUICtrlListView_AddItem($hListView_Right, "Peter " & $i - 1)
    If Mod($i, 4) Then
        _GUICtrlListView_AddSubItem($hListView_Right, $i - 1, "Paul " & $i - 1, 1)
    EndIf
    _GUICtrlListView_AddSubItem($hListView_Right, $i - 1, "Mary " & $i - 1, 2)
Next

; Read array from Right  ListView
Global $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 1)
; The array as read from Right ListView and used subsequently
;_ArrayDisplay($aLV_List_Right, "Read from Right ListView")

; Initiate LVEx - use read content as array - count parameter set - red insert mark - drag image - editable - all cols editable by default (plus headers)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 1, 0xFF0000, True, 2 + 4 + 8 + 16)

; Create Edit Mode Combos
GUICtrlCreateLabel("Edit Modes", 330, 50, 60, 20)
GUICtrlCreateLabel("0" & @CRLF & "1" & @CRLF & "2" & @CRLF & "3", 330, 70, 10, 80)
GUICtrlCreateLabel(":  Single Edit" & @CRLF & ":  Exit Edge" & @CRLF & ":  Stay Edge" & @CRLF & ":  Loop Edge", 340, 70, 65, 80)
GUICtrlCreateLabel("Row Mode", 330, 140, 60, 20)
$cCombo_Row = GUICtrlCreateCombo("", 330, 160, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Row, "0|1|2|3", 0)
GUICtrlCreateLabel("Col Mode", 330, 200, 60, 20)
$cCombo_Col = GUICtrlCreateCombo("", 330, 220, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Col, "0|1|2|3", 0)
GUICtrlCreateLabel("ESC Mode", 330, 260, 75, 20)
$cCombo_Reset = GUICtrlCreateCombo("", 330, 280, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Reset, "Exit Edit|Reset All", "Exit Edit")

; Create buttons
$cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30)
$cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30)
$cUp_Button = GUICtrlCreateButton("Move Up", 220, 350, 200, 30)
$cDown_Button = GUICtrlCreateButton("Move Down", 220, 390, 200, 30)
$cEdit_Left_Button = GUICtrlCreateButton("Edit Left 1,1", 10, 430, 200, 30)
$cEdit_Right_Button = GUICtrlCreateButton("Edit Right 5,0", 220, 430, 200, 30)
$cDelAll_Left_Button = GUICtrlCreateButton("Delete All Left", 10, 470, 200, 30)
$cDelAll_Right_Button = GUICtrlCreateButton("Delete All Right", 220, 470, 200, 30)
$cDisplay_Left_Button = GUICtrlCreateButton("Show Left", 430, 350, 100, 30)
$cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30)
$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

GUISetState()

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

; Set the left ListView as active
_GUIListViewEx_SetActive($iLV_Left_Index)

Switch _GUIListViewEx_GetActive()
    Case 0
        $sMsg = "No ListView is active"
    Case 1
        $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------"
    Case 2
        $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->"
EndSwitch
;MsgBox(0, "Active ListView", $sMsg)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit

        Case $cInsert_Button
            ; Prepare data  for insertion
            Switch $aGLVEx_Data[0][1]
                Case 1
                    ; String format with multi-column native ListView
                    $vData = "Tom " & $iCount_Left & "|Dick " & $iCount_Left & "|Harry " & $iCount_Left
                    $iCount_Left += 1
                    _GUIListViewEx_Insert($vData)
                Case 2
                    ; Array format with multi-column UDF ListView
                    Global $vData[3] = ["Peter " & $iCount_Right, "Paul " & $iCount_Right, "Mary " & $iCount_Right]
                    $iCount_Right += 1
                    _GUIListViewEx_Insert($vData)
            EndSwitch

        Case $cDelete_Button
            _GUIListViewEx_Delete()

        Case $cUp_Button
            _GUIListViewEx_Up()

        Case $cDown_Button
            _GUIListViewEx_Down()

        Case $cDisplay_Left_Button

            $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index)
            If Not @error Then
                _ArrayDisplay($aLV_List_Left, "Returned Left")
            Else
                MsgBox(0, "Left", "Empty Array")
            EndIf
            $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index, 1)
            If Not @error Then
                _ArrayDisplay($aLV_List_Left, "Returned Left Checkboxes")
            Else
                MsgBox(0, "Left", "Empty Check Array")
            EndIf

        Case $cDisplay_Right_Button

            $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index)
            If Not @error Then
                _ArrayDisplay($aLV_List_Right, "Returned Right")
            Else
                MsgBox(0, "Right", "Empty Array")
            EndIf

        Case $cEdit_Left_Button
            ; Note abilty to edit columns which cannot be edited via doubleclick
            $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 1, 1, $iEditMode) ; Use combos to change EditMode
            ; Check array exists
            If IsArray($aRet) Then
                ; Uncomment to see returned array
                ;_ArrayDisplay($aRet, @error)
            EndIf

        Case $cEdit_Right_Button
            $aHdr_Ret = _GUIListViewEx_EditItem($iLV_Right_Index, 5, 0, $iEditMode) ; Use combos to change EditMode
            $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 1, 1, $iEditMode) ; Use combos to change EditMode
            ; Check array exists
            If IsArray($aRet) Then
                ; Uncomment to see returned array
                ;_ArrayDisplay($aRet, @error)
            EndIf

        Case $cDelAll_Left_Button ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ConsoleWrite("Prev Index = " & $iLV_Left_Index & @CRLF)
            ; Clear ListView from UDF
            _GUIListViewEx_Close($iLV_Left_Index)
            ; Delete all items
            _GUICtrlListView_DeleteAllItems($cListView_Left)
            ; Re-initiate ListView - no array
            $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, "", 0, 0, True, 1 + 2 + 8, "0;2")
            ConsoleWrite("New Index = " & $iLV_Left_Index & @CRLF)
            ; Activate ListView
            _GUIListViewEx_SetActive($iLV_Left_Index)


        Case $cDelAll_Right_Button
            ConsoleWrite("Prev Index = " & $iLV_Right_Index & @CRLF)
            ; Clear ListView from UDF
            _GUIListViewEx_Close($iLV_Right_Index)
            ; Delete all items
            _GUICtrlListView_DeleteAllItems($hListView_Right)
            ; Re-initiate ListView - no array
            $iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, "", 1, 0xFF0000, True, 2 + 4 + 8 + 16)
            ConsoleWrite("New Index = " & $iLV_Right_Index & @CRLF)
            ; Activate ListView
            _GUIListViewEx_SetActive($iLV_Right_Index)

        Case $cCombo_Row
            Switch GUICtrlRead($cCombo_Row)
                Case 0
                    ; Both must be set to 0
                    GUICtrlSetData($cCombo_Col, 0)
                Case Else
                    ; Neither must be set to 0 - so match selections
                    If GUICtrlRead($cCombo_Col) = 0 Then
                        GUICtrlSetData($cCombo_Col, GUICtrlRead($cCombo_Row))
                    EndIf
            EndSwitch
            ; Set required edit mode
            $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col))

        Case $cCombo_Col
            Switch GUICtrlRead($cCombo_Col)
                Case 0
                    GUICtrlSetData($cCombo_Row, 0)
                Case Else
                    If GUICtrlRead($cCombo_Row) = 0 Then
                        GUICtrlSetData($cCombo_Row, GUICtrlRead($cCombo_Col))
                    EndIf
            EndSwitch
            $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col))

        Case $cCombo_Reset
            ; Toggle edit mode value to switch ESC modes
            $iEditMode *= -1

    EndSwitch

    $aRet = _GUIListViewEx_EditOnClick($iEditMode) ; Use combos to change EditMode
    ; Array only returned AFTER EditOnClick process - so check array exists
    If IsArray($aRet) Then
        ; Uncomment to see returned array
        ;_ArrayDisplay($aRet, @error)
    EndIf

WEnd
All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Kovacic,

As I suspected it is not difficult to do. You need get the UDF to stop tracking the ListView in question with _GUIListViewEx_Close, empty it using the already suggested _GUICtrlListView_DeleteAllItems, and then re-initialise the ListView with _GUIListViewEx_Init using an empty array. :)

There is no problem with the index. Firstly, the UDF looks for the first blank element in the list, so the chances are that it will be the one you just closed and so it will use that and actually return the same index. Secondly, if you store the index in a variable then you can just reassign the new index to that variable and it really does not matter at all what the actual value is - I hope you were not hard coding it! :o

Here is an example script with 2 buttons which empty the 2 ListViews. Look for the <<<<<<<<<< section to see the code used:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIListViewEx.au3"

#include <Array.au3> ; Just for display in example

Opt("GUICloseOnESC", 0)

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" & @CRLF & "Multiple selection - no count - sort && editable (0 && 2)", 10, 5, 300, 30)

$cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)
; 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 - sort & editable - only cols 0 & 2 (plus headers) editable
$iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, $aLV_List_Left, 0, 0, True, 1 + 2 + 8, "0;2")

; Create Right ListView
GUICtrlCreateLabel("UDF ListView" & @CRLF & "Single sel - count element - editable (all)", 430, 5, 300, 30)

$hListView_Right = _GUICtrlListView_Create($hGUI, "", 430, 40, 200, 300, BitOR($LVS_DEFAULT, $WS_BORDER))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_AddColumn($hListView_Right, "Peter", 83)
_GUICtrlListView_AddColumn($hListView_Right, "Paul", 83)
_GUICtrlListView_AddColumn($hListView_Right, "Mary", 83)

_GUICtrlListView_SetTextBkColor($hListView_Right, 0xDDFFDD)

; Fill Right ListView
For $i = 1 To $iCount_Right
    _GUICtrlListView_AddItem($hListView_Right, "Peter " & $i - 1)
    If Mod($i, 4) Then
        _GUICtrlListView_AddSubItem($hListView_Right, $i - 1, "Paul " & $i - 1, 1)
    EndIf
    _GUICtrlListView_AddSubItem($hListView_Right, $i - 1, "Mary " & $i - 1, 2)
Next

; Read array from Right  ListView
Global $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 1)
; The array as read from Right ListView and used subsequently
;_ArrayDisplay($aLV_List_Right, "Read from Right ListView")

; Initiate LVEx - use read content as array - count parameter set - red insert mark - drag image - editable - all cols editable by default (plus headers)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 1, 0xFF0000, True, 2 + 4 + 8 + 16)

; Create Edit Mode Combos
GUICtrlCreateLabel("Edit Modes", 330, 50, 60, 20)
GUICtrlCreateLabel("0" & @CRLF & "1" & @CRLF & "2" & @CRLF & "3", 330, 70, 10, 80)
GUICtrlCreateLabel(":  Single Edit" & @CRLF & ":  Exit Edge" & @CRLF & ":  Stay Edge" & @CRLF & ":  Loop Edge", 340, 70, 65, 80)
GUICtrlCreateLabel("Row Mode", 330, 140, 60, 20)
$cCombo_Row = GUICtrlCreateCombo("", 330, 160, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Row, "0|1|2|3", 0)
GUICtrlCreateLabel("Col Mode", 330, 200, 60, 20)
$cCombo_Col = GUICtrlCreateCombo("", 330, 220, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Col, "0|1|2|3", 0)
GUICtrlCreateLabel("ESC Mode", 330, 260, 75, 20)
$cCombo_Reset = GUICtrlCreateCombo("", 330, 280, 75, 20, 0x3) ; $CBS_DROPDOWNLIST
GUICtrlSetData($cCombo_Reset, "Exit Edit|Reset All", "Exit Edit")

; Create buttons
$cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30)
$cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30)
$cUp_Button = GUICtrlCreateButton("Move Up", 220, 350, 200, 30)
$cDown_Button = GUICtrlCreateButton("Move Down", 220, 390, 200, 30)
$cEdit_Left_Button = GUICtrlCreateButton("Edit Left 1,1", 10, 430, 200, 30)
$cEdit_Right_Button = GUICtrlCreateButton("Edit Right 5,0", 220, 430, 200, 30)
$cDelAll_Left_Button = GUICtrlCreateButton("Delete All Left", 10, 470, 200, 30)
$cDelAll_Right_Button = GUICtrlCreateButton("Delete All Right", 220, 470, 200, 30)
$cDisplay_Left_Button = GUICtrlCreateButton("Show Left", 430, 350, 100, 30)
$cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30)
$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

GUISetState()

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

; Set the left ListView as active
_GUIListViewEx_SetActive($iLV_Left_Index)

Switch _GUIListViewEx_GetActive()
    Case 0
        $sMsg = "No ListView is active"
    Case 1
        $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------"
    Case 2
        $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->"
EndSwitch
;MsgBox(0, "Active ListView", $sMsg)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit

        Case $cInsert_Button
            ; Prepare data  for insertion
            Switch $aGLVEx_Data[0][1]
                Case 1
                    ; String format with multi-column native ListView
                    $vData = "Tom " & $iCount_Left & "|Dick " & $iCount_Left & "|Harry " & $iCount_Left
                    $iCount_Left += 1
                    _GUIListViewEx_Insert($vData)
                Case 2
                    ; Array format with multi-column UDF ListView
                    Global $vData[3] = ["Peter " & $iCount_Right, "Paul " & $iCount_Right, "Mary " & $iCount_Right]
                    $iCount_Right += 1
                    _GUIListViewEx_Insert($vData)
            EndSwitch

        Case $cDelete_Button
            _GUIListViewEx_Delete()

        Case $cUp_Button
            _GUIListViewEx_Up()

        Case $cDown_Button
            _GUIListViewEx_Down()

        Case $cDisplay_Left_Button

            $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index)
            If Not @error Then
                _ArrayDisplay($aLV_List_Left, "Returned Left")
            Else
                MsgBox(0, "Left", "Empty Array")
            EndIf
            $aLV_List_Left = _GUIListViewEx_ReturnArray($iLV_Left_Index, 1)
            If Not @error Then
                _ArrayDisplay($aLV_List_Left, "Returned Left Checkboxes")
            Else
                MsgBox(0, "Left", "Empty Check Array")
            EndIf

        Case $cDisplay_Right_Button

            $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index)
            If Not @error Then
                _ArrayDisplay($aLV_List_Right, "Returned Right")
            Else
                MsgBox(0, "Right", "Empty Array")
            EndIf

        Case $cEdit_Left_Button
            ; Note abilty to edit columns which cannot be edited via doubleclick
            $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 1, 1, $iEditMode) ; Use combos to change EditMode
            ; Check array exists
            If IsArray($aRet) Then
                ; Uncomment to see returned array
                ;_ArrayDisplay($aRet, @error)
            EndIf

        Case $cEdit_Right_Button
            $aHdr_Ret = _GUIListViewEx_EditItem($iLV_Right_Index, 5, 0, $iEditMode) ; Use combos to change EditMode
            $aRet = _GUIListViewEx_EditItem($iLV_Left_Index, 1, 1, $iEditMode) ; Use combos to change EditMode
            ; Check array exists
            If IsArray($aRet) Then
                ; Uncomment to see returned array
                ;_ArrayDisplay($aRet, @error)
            EndIf

        Case $cDelAll_Left_Button ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ConsoleWrite("Prev Index = " & $iLV_Left_Index & @CRLF)
            ; Clear ListView from UDF
            _GUIListViewEx_Close($iLV_Left_Index)
            ; Delete all items
            _GUICtrlListView_DeleteAllItems($cListView_Left)
            ; Re-initiate ListView - no array
            $iLV_Left_Index = _GUIListViewEx_Init($cListView_Left, "", 0, 0, True, 1 + 2 + 8, "0;2")
            ConsoleWrite("New Index = " & $iLV_Left_Index & @CRLF)
            ; Activate ListView
            _GUIListViewEx_SetActive($iLV_Left_Index)


        Case $cDelAll_Right_Button
            ConsoleWrite("Prev Index = " & $iLV_Right_Index & @CRLF)
            ; Clear ListView from UDF
            _GUIListViewEx_Close($iLV_Right_Index)
            ; Delete all items
            _GUICtrlListView_DeleteAllItems($hListView_Right)
            ; Re-initiate ListView - no array
            $iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, "", 1, 0xFF0000, True, 2 + 4 + 8 + 16)
            ConsoleWrite("New Index = " & $iLV_Right_Index & @CRLF)
            ; Activate ListView
            _GUIListViewEx_SetActive($iLV_Right_Index)

        Case $cCombo_Row
            Switch GUICtrlRead($cCombo_Row)
                Case 0
                    ; Both must be set to 0
                    GUICtrlSetData($cCombo_Col, 0)
                Case Else
                    ; Neither must be set to 0 - so match selections
                    If GUICtrlRead($cCombo_Col) = 0 Then
                        GUICtrlSetData($cCombo_Col, GUICtrlRead($cCombo_Row))
                    EndIf
            EndSwitch
            ; Set required edit mode
            $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col))

        Case $cCombo_Col
            Switch GUICtrlRead($cCombo_Col)
                Case 0
                    GUICtrlSetData($cCombo_Row, 0)
                Case Else
                    If GUICtrlRead($cCombo_Row) = 0 Then
                        GUICtrlSetData($cCombo_Row, GUICtrlRead($cCombo_Col))
                    EndIf
            EndSwitch
            $iEditMode = Number(GUICtrlRead($cCombo_Row) & GUICtrlRead($cCombo_Col))

        Case $cCombo_Reset
            ; Toggle edit mode value to switch ESC modes
            $iEditMode *= -1

    EndSwitch

    $aRet = _GUIListViewEx_EditOnClick($iEditMode) ; Use combos to change EditMode
    ; Array only returned AFTER EditOnClick process - so check array exists
    If IsArray($aRet) Then
        ; Uncomment to see returned array
        ;_ArrayDisplay($aRet, @error)
    EndIf

WEnd
All clear? :)

M23

 

Much Thanks Melba!! I start working on this app again today at 1 EST and will let you know how it works out, but i'm sure it will be fine. 

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

Im back ;)

Ok so for my function to clear a GUIListView ( ID number 2 ) I have this:

func ClearSearch() ; Clear search from tab 4
_GUIListViewEx_Close(2)
_GUICtrlListView_DeleteAllItems(2)
_GUIListViewEx_Init(2, "", 0, 0x00FF00)
endfunc

It closes the UDF functions from Index 2, then tries to clear all items, then re initializes the control, but it seems like its not doing anything to the list.

I know im missing something

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

You need the handle or control ID of the listview, not sure what the 2 you're using is from.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Kovacic,

Glad it worked :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK so that worked... I am left with one more issue.. After I clear the form, if I do another search, it brings back the old data that was cleared out, and I broke it down to my one line item to add new data, the line that calls _GUIListViewEx_Insert

here is the function:

func ExSearch() ; Execute search for tab 4
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
Local $zHe = 50, $Wze = 400
    Local $splash = GUICreate('', $Wze, $zHe, Default, Default, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)
    GUICtrlCreateGroup('SEARCHING...', 0, -5, $Wze, $zHe + 5, $WS_THICKFRAME)
    GUICtrlSetFont(-1, 14, 800, 0, "Arial", 5)
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    GUICtrlCreateProgress(10, 20, 380, 25, 0x00000008)
    _SendMessage(GUICtrlGetHandle(-1), $PBM_SETMARQUEE, True, 50)
    ;GUISetState(@SW_SHOW, $splash)
    MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
$string = guictrlread($sbox)
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
$object = guictrlread($SearchCombo)
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
$conn.Open($DSN)
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
    $rs = ObjCreate("ADODB.RecordSet")
    MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
    ;Msgbox(0,"EXECUTING","SELECT * FROM [v_master] where '" & $object & "'='" & $string & "';")
    $rs.Open("SELECT * FROM [v_master] where [" & $object & "]='" & $string & "';", $conn)
    MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
            _GUIListViewEx_Close($resultlist)
            _GUICtrlListView_DeleteAllItems($resultlist)
            _GUIListViewEx_Init($resultlist, "", 0, 0x00FF00)
            _GUIListViewEx_SetActive($resultlist)
            MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
    If $rs.RecordCount Then
    MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
        While Not $rs.EOF
        MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
        sleep(1000)
        MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
            $z1 = StringStripWS($rs.Fields("Serial Number").Value, 8)
            $z2 = StringStripWS($rs.Fields("Last User").Value, 8)
            $z3 = StringStripWS($rs.Fields("Owner").Value, 8)
            $z4 = StringStripWS($rs.Fields("Status").Value, 8)
            $z12 = StringStripWS($rs.Fields("Status").Value, 8)
            $z13 = StringStripWS($rs.Fields("Status").Value, 8)
            $z5 = StringStripWS($rs.Fields("Model").Value, 8)
            $z6 = StringStripWS($rs.Fields("Building").Value, 8)
            $z7 = StringStripWS($rs.Fields("Floor").Value, 8)
            $z8 = StringStripWS($rs.Fields("Side").Value, 8)
            $z9 = StringStripWS($rs.Fields("Area").Value, 8)
            $z10 = StringStripWS($rs.Fields("Unit").Value, 8)
            $z11 = StringStripWS($rs.Fields("Shelf").Value, 8)
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
            _GUIListViewEx_Insert($z1 & " | " & $z2 & " | " & $z3 & " | " & $z4 & " | " & $z12 & " | " & $z13 & " | " & $z5 & " | " & $z6 & " | " & $z7 & " | " & $z8 & " | " & $z9 & " | " & $z10 & " | " & $z11)
    MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
            $rs.MoveNext
            MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
        WEnd
MSGBOX(0,"DEBUG","THIS BOX IS ON LINE " & @ScriptLineNumber)
    EndIf
    
;GUIDelete($splash)
endfunc

Ignore all the message boxes, they are just used to see where the values were coming back..

This line is what brings back the old data once its cleared:

_GUIListViewEx_Insert($z1 & " | " & $z2 & " | " & $z3 & " | " & $z4 & " | " & $z12 & " | " & $z13 & " | " & $z5 & " | " & $z6 & " | " & $z7 & " | " & $z8 & " | " & $z9 & " | " & $z10 & " | " & $z11)

and I am wondering if a value in the UDF is holding on to the previous values..

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Link to comment
Share on other sites

  • Moderators

Kovacic,

All that snippet tells me is that it should not work. ;)

_GUIListViewEx_Close($resultlist)                 ; Should be the index returned from _GUIListViewEx_Init
_GUICtrlListView_DeleteAllItems($resultlist)      ; Should be the handle/ControlID returned by GUICtrlCreateListView/_GUICrtlListView_Create
_GUIListViewEx_Init($resultlist, "", 0, 0x00FF00) ; Here you need to store the new index retuned by the function...
_GUIListViewEx_SetActive($resultlist)             ; ...which you then use here
So using the same variable for all of these is very unlikely to give you what you think you should get. Please ask if you do not understand my comments - they are pretty fundamental to the script working correctly. :)

 

I am wondering if a value in the UDF is holding on to the previous values

As you are reassigning those variables in the code I cannot believe that the UDF has anything to do with what you are seeing - all it does is track what you put into the ListView and you have just reintialised it with an empty array. The data you which you assign to those variables and then insert is coming from your database query - I suggest that is where you look. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

×
×
  • Create New...