Sign in to follow this  
Followers 0
timdecker

_GUICtrlListView_DeleteAllItems - Similar

6 posts in this topic

Is there a similar function or method of "_GUICtrlListView_DeleteAllItems" that can be used to remove checkboxes?

Thanks,

Tim

Share this post


Link to post
Share on other sites



This post by Melba23 could point you in the right direction: >link


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

This post by Melba23 could point you in the right direction: >link

 

Thanks MikahS, but that is applying to checkboxes in listview....

How about something for GUICtrlCreateCheckbox that is not inside of a listview?

Thanks,

Tim

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is there a similar function or method of "_GUICtrlListView_DeleteAllItems" that can be used to remove checkboxes?

 

No, there is no such function for what you want.

But it's simple, just store control IDs od checkboxes as returned by GUICtrCreateCheckbox() into your array.

And later when you want to delete them, just go through that array by FOR/NEXT loop and call something like this:

GUICtrlDelete($array_cbx[$i])
Edited by Zedna

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

My apologies.  :sweating:

Zedna's idea is a good one, but you can also just set the state to hide the control completely with:

GUICtrlSetState

Do as Zedna stated and store your checkbox controls into an array, then loop through them with a for..next loop.

Local $i
For $i = 0 To Ubound($checkboxArray) - 1 Step 1
    GUICtrlSetState($checkboxArray[$i], $GUI_HIDE)
Next

EDIT: That is if you're not trying to delete them, or do something with them later.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

 

No, there is no such function for what you want.

But it's simple, just store control IDs od checkboxes as returned by GUICtrCreateCheckbox() into your array.

And later when you want to delete them, just go through that array by FOR/NEXT loop and call something like this:

GUICtrlDelete($array_cbx[$i])

 

Thanks a bunch!

I added this:

For $i = 1 To $iCount
   GUICtrlDelete($aCheck[$i])
Next

And then re-added this, to build it again when I selected a new file:

$checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    For $j = 1 To $iCount
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
    Next

Also, here is the complete code:

#include <file.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <GuiComboBox.au3>
#include <StaticConstants.au3>

Global $a_csv
Global $listview
Global $checkboxName
Global $iCount
Global $runProg
Global $acheck
Global $mapColumn
Global $runProg
Global $selectInstrument
Global $selectFile
Global $s_Path


$s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)")
If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    Exit
Else

    _FileReadToArray($s_Path, $a_csv)
    buildGUI()




EndIf



Func _loadNewFile()
    _FileReadToArray(GUICtrlRead($selectFile),$a_csv)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210)
    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next



    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    For $j = 1 To $iCount
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
    Next


EndFunc


Func copyToInput()
    Select
        Case GUICtrlRead($selectInstrument) = "dummy"
            $textPos = 4
            $title = "HPOV"
        Case GUICtrlRead($selectInstrument) = "TGA-100"
            $textPos = 35
            $title = "(METTLER) - TGA-100A with gas box"
        Case GUICtrlRead($selectInstrument) = "TGA-200"
            $textPos = 44
            $title = "(METTLER) - TGA-200A with gas box"
        Case GUICtrlRead($selectInstrument) = "AUTOCAT-100"
            $textPos = 75
        Case GUICtrlRead($selectInstrument) = "AUTOCAT-200"
            $textPos = 15
    EndSelect


    $allRows =  _GUICtrlListView_GetItemCount($listview)
    For $rows = 0 to $allRows-1
        $material_name = _GUICtrlListView_GetItem($listview, $rows, 0)
        $letter = _GUICtrlListView_GetItem($listview, $rows, 3)

        If GUICtrlRead($aCheck[1]) <> 1 and GUICtrlRead($aCheck[4]) <> 1 then continueloop

            If GUICtrlRead($aCheck[1]) = 1 Then
                controlsettext($title, "", $textPos, $material_name[3])
            endif
#cs - 2nd input box
            If GUICtrlRead($aCheck[4]) = 1 Then
                controlsettext($title, "", 5, $letter[3])
            endif
#ce

            controlclick($title, "", 6)

            Sleep(2000)

        ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation

        ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads

            controlclick("Job", "", 2)

            Sleep(2000)
        ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation

        ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads
            if msgbox(1,"", "You Shall Not Pass!" & @CRLF & "Ok actually you can, just press something") = 2 then
    ExitLoop
    endif
    Next
EndFunc

Func buildGUI()


    GUICreate("CSV Listview", 900, 450, -1, -1)
    $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210)
    GUICtrlCreateLabel("Select a sample file:", 450, 40, 200)
    $selectFile = GUICtrlCreateCombo("", 450, 60, 180, 200)
    _GUICtrlComboBox_BeginUpdate($selectFile)
    _GUICtrlComboBox_AddDir($selectFile, @ScriptDir & "\*.csv")
    _GUICtrlComboBox_EndUpdate($selectFile)
    $loadNewFile = GUICtrlCreateButton("Load File", 450, 80)

    GUICtrlCreateLabel("Select an instrument:", 700, 40, 200)
    $selectInstrument = GUICtrlCreateCombo("", 700, 60, 180, 25)
    GUICtrlSetData(-1, "dummy|TGA-100|TGA-200|AUTOCAT-100|AUTOCAT-200")

    $checkboxName = StringSplit($a_csv[1], ",")
    $iCount = $checkboxName[0]

;creating buttons
    ;$runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30)
    $runProg = GUICtrlCreateButton("Run Program", 700, 330, 180, 30)
    GUICtrlSetState($runProg, $GUI_DISABLE)

;Building the checkboxes DYNAMICALLY....may need to switch to forced checkbox name
;Store controIDs of the checkboxes
    Global $aCheck[$iCount + 1]
    Global $mapColumn[$iCount + 1]
    For $j = 1 To $iCount
        $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30)
        GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED)
        ;$mapColumn[$j] = GUICtrlCreateButton("Map " & '"'  & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30)
        ;GUICtrlSetState($mapColumn[$j], $GUI_DISABLE)
    Next

    For $i = 2 To UBound($a_csv) - 1
        $s_temp = StringReplace($a_csv[$i], ",", "|")
        GUICtrlCreateListViewItem($s_temp, $listview)
    Next

    Global $aOut['']['']
    For $i = 2 to $a_csv[0]
        $aLine = stringsplit($a_csv[$i] , ",",3)
            If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)]
            _ArrayAdd($aOut , $a_csv[$i] , 0 , ",")
           ; consolewrite("line: "  & $aLine[2] & @LF)
    Next




    Local $idCancelbutton = GUICtrlCreateButton("Exit", 700, 370, 180, 30)


   ; GUISetState(@SW_SHOW)



    GUISetState()

    While 1
        $msg = GUIGetMsg()
            Switch $msg
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $runProg
                    copyToInput()
                Case $loadNewFile
                    _GUICtrlListView_DeleteAllItems($listview)

                    For $i = 1 To $iCount
                        GUICtrlDelete($aCheck[$i])
                    Next



                    _loadNewFile()
                Case $GUI_EVENT_CLOSE, $idCancelbutton
                    ExitLoop
                Case Else
                    For $i = 1 To $iCount
                        If $msg = $aCheck[$i] Then
                            If GUICtrlRead($msg) = 1 Then
                                ;GUICtrlSetState($mapColumn[$i], $GUI_ENABLE)
                                GUICtrlSetState($runProg, $GUI_ENABLE)

                                ;Local $text = ""
                                ;   For $k = 0 to $a_csv[0]-1
                                ;     $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf
                                ;   Next
                                ;   Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected
                            Else
                                ;GUICtrlSetState($mapColumn[$i], $GUI_DISABLE)
                                GUICtrlSetState($runProg, $GUI_DISABLE)
                            EndIf
                    ExitLoop
                            EndIf
                    Next
            EndSwitch
    WEnd
    GUIDelete()
EndFunc

Thanks again for the help guys!

Tim

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