Probleme beim Löschen einer ListBox

  • Hallo Community 8o

    Ich habe ein Problem.

    Spoiler anzeigen
    [autoit]

    #include
    #include
    #include
    #include
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 317, 233, 192, 124)
    $List1 = GUICtrlCreateList("", 8, 8, 169, 201)
    GUICtrlSetData(-1, "Text1|Text2|Text3|Text4|Text5")
    $deleteall = GUICtrlCreateButton("Alle Löschen", 184, 16, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $deleteall
    $iCount = _GUICtrlListBox_GetCount($List1)
    for $i = 0 to $iCount
    _GUICtrlListBox_DeleteString($List1, $i)
    Next
    EndSwitch
    WEnd

    [/autoit]


    Bei dem Skript müssten normal alle Werte gelöscht werden...Warum funzt das nicht?

    [autoit]


    While $Life = True
    $nMSG = BrainGetMsg()
    Switch $nMSG
    Case $Idea
    _Convert_Idea2Code()
    EndSwitch
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von GE IXI TIM (10. September 2010 um 00:26)

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 317, 233, 192, 124)
    $List1 = GUICtrlCreateList("", 8, 8, 169, 201)
    GUICtrlSetData(-1, "Text1|Text2|Text3|Text4|Text5")
    $deleteall = GUICtrlCreateButton("Alle Löschen", 184, 16, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $deleteall
    _GUICtrlListBox_ResetContent($List1)
    EndSwitch
    WEnd

    [/autoit]
  • Erstmal danke :thumbup: Klappt wunderbar..
    aber:
    1. Ist diese Funktion iwie neu oO Hab die noch nie gesehen...
    2. Warum funzt mein Script nicht? Müsste doch auch laufen...

    Grüße, Tim :)

    [autoit]


    While $Life = True
    $nMSG = BrainGetMsg()
    Switch $nMSG
    Case $Idea
    _Convert_Idea2Code()
    EndSwitch
    WEnd

    [/autoit]
    • Offizieller Beitrag

    1. Die Funktion ist nicht neu.
    2. Du hast einen Denkfehler im Script. Du löschst von 0 bis 5, das kann nicht gehen, da nach jedem löschen die Items neu indexiert werden.
    Man löscht von 5 bis 0 ;)

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 317, 233, 192, 124)
    $List1 = GUICtrlCreateList("", 8, 8, 169, 201)
    GUICtrlSetData(-1, "Text1|Text2|Text3|Text4|Text5")
    $deleteall = GUICtrlCreateButton("Alle Löschen", 184, 16, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $deleteall
    $iCount = _GUICtrlListBox_GetCount($List1)
    For $i = $iCount To 0 Step -1
    _GUICtrlListBox_DeleteString($List1, $i)
    Next
    EndSwitch
    WEnd

    [/autoit]
  • zu 2.: Das liegt daran dass der Index nach jedem Löschvorgang aktualisiert wird:
    beim 1. Mal wird Index 0 gelöscht, dadurch rücken alle um 1 hoch
    beim 2. Mal wird Index 1 gelöscht (der vorher 2 war
    irgendwann gibt es auch die Index-Nr. zum Löschen nicht mehr.

    Wenn du von hinten anfängst klappt deine Methode.

    Anhand dieses Skriptes kannst du das Verhalten beobachten:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIListBox.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 317, 233, 192, 124)
    $List1 = GUICtrlCreateList("", 8, 8, 169, 201)
    $deleteall = GUICtrlCreateButton("Alle Löschen richtig", 184, 16, 125, 25, $WS_GROUP)
    $deletewrong = GUICtrlCreateButton("Alle Löschen falsch", 184, 40, 125, 25, $WS_GROUP)
    $createNew = GUICtrlCreateButton("neu erzege", 184, 70, 125, 25, $WS_GROUP)
    $ItemCount = GUICtrlCreateLabel("", 184, 100, 125, 25)
    createNew()
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    #endregion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $deleteall
    $iCount = _GUICtrlListBox_GetCount($List1)
    For $i = $iCount To 0 Step -1
    _GUICtrlListBox_DeleteString($List1, $i)
    GUICtrlSetData($ItemCount,$i & "/" & _GUICtrlListBox_GetCount($List1))
    Sleep(500)
    Next
    Case $deletewrong
    $iCount = _GUICtrlListBox_GetCount($List1)
    For $i = 0 To $iCount
    _GUICtrlListBox_DeleteString($List1, $i)
    GUICtrlSetData($ItemCount,$i & "/" & _GUICtrlListBox_GetCount($List1))
    Sleep(500) ;evtl. höher setzen damit es besser sichtbar wird
    Next
    Case $createNew
    createNew()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func createNew()
    _GUICtrlListBox_ResetContent($List1)
    For $i = 0 To 99
    _GUICtrlListBox_AddString($List1, $i & ".Test")
    Next
    GUICtrlSetData($ItemCount, "Nei: " & _GUICtrlListBox_GetCount($List1))
    EndFunc ;==>createNew

    [/autoit]

    und da dein Problem jetzt ja gelöst, wäre es schön wenn du auch den Thread auf gelöst setzt. Einfach 1. Beitrag bearbeiten, Präfix (nähe Überschrift) ändern und speichern (absenden)

    Edit: Raupi war deutlich schneller mit der Erklärung

    mfg autoBert

  • Okay danke für die Erklärung :D
    Da muss man aber auch erst mal draufkommen^^

    [autoit]


    While $Life = True
    $nMSG = BrainGetMsg()
    Switch $nMSG
    Case $Idea
    _Convert_Idea2Code()
    EndSwitch
    WEnd

    [/autoit]
  • Um das Beispiel von i2c mal aufzugreifen:
    Es geht auch ohne ListBox Include:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 317, 233, 192, 124)
    $List1 = GUICtrlCreateList("", 8, 8, 169, 201)
    GUICtrlSetData(-1, "Text1|Text2|Text3|Text4|Text5")
    $deleteall = GUICtrlCreateButton("Alle Löschen", 184, 16, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $deleteall
    GUICtrlSetData($List1,"")
    EndSwitch
    WEnd

    [/autoit]
  • Nachmal zur Erklärung von SEuBo's Vorschlag.
    Auszug aus der Hilfe zu GUICtrlSetData:

    Code
    Wenn "data" mit dem über GUIDataSeparatorChar definierten Zeichen beginnt oder
    einen leeren String ist (""), wird die vorherige Liste gelöscht.