Jump to content

Remove items from listbox after a selection is made


Recommended Posts

Hello,

I am trying to delete items from a listbox after the item has been moved to another listbox. For eg: from Listbox1 when I move an item into Listbox2, I need to delete it in Listbox1. Can someone please help? Thanks!

Here is my partial code.

Func Selectapps()

$Count = 0

GUICreate("List of apps to be selected")

$ListofApps = GUICtrlCreateList("", 10, 10, 120, 320)

While $Count < $appIdCount

GUICtrlSetData($ListofApps, $AppIdProc[$Count][0], "")

$Count = $Count + 1

WEnd

$AppsAdded = GuiCtrlCreateList("", 200, 10, 120, 320)

$moverightbtn1 = GuiCtrlCreateButton(">>",150,100,40,20)

$moveleftbtn1 = GuiCtrlCreateButton("<<",150,130,40,0)

GUISetState()

$Count1 = 0

While 1

$button = GUIGetMsg()

If $button = $GUI_EVENT_ClOSE Then

ExitLoop

EndIf

If $button = $moverightbtn1 Then

$rightmoveitem = GuiCtrlRead($ListofApps)

ConsoleWrite($rightmoveitem & @CRLF)

GuiCtrlSetdata($AppsAdded, $rightmoveitem)

$Count1 = $Count + 1

EndIf

If $button = $moveleftbtn1 Then

$leftmoveitem = GuiCtrlRead($AppsAdded)

ConsoleWrite($leftmoveitem & @CRLF)

GuiCtrlSetdata($ListofApps, $leftmoveitem)

$Count1 = $Count + 1

EndIf

WEnd

EndFunc

Link to comment
Share on other sites

Put [code][/code] tags around your code, please.

This is one way:

#include <GuiConstantsEx.au3>
#include <GuiListBox.au3>

Global $AppIdProc[5][2] = [["Audigy", ""],["Firefox", ""],["LibreOffice", ""],["Gimp", ""],["WINE", ""]], $appIdCount = 5

Selectapps()

Func Selectapps()

    $Count = 0

    GUICreate("List of apps to be selected")
    $ListofApps = GUICtrlCreateList("", 10, 10, 120, 320)
    While $Count < $appIdCount
        GUICtrlSetData($ListofApps, $AppIdProc[$Count][0], "")
        $Count = $Count + 1
    WEnd
    $AppsAdded = GUICtrlCreateList("", 200, 10, 120, 320)
    $moverightbtn1 = GUICtrlCreateButton(">>", 150, 100, 40, 20)
    $moveleftbtn1 = GUICtrlCreateButton("<<", 150, 130, 40, 0)
    GUISetState()

    $Count1 = 0
    While 1
        $button = GUIGetMsg()
        If $button = $GUI_EVENT_ClOSE Then
            ExitLoop
        EndIf
        If $button = $moverightbtn1 Then
            $rightmoveitem = GUICtrlRead($ListofApps)
            If StringStripWS($rightmoveitem, 8) Then
                ConsoleWrite($rightmoveitem & @CRLF)
                GUICtrlSetData($AppsAdded, $rightmoveitem)
                $iSel = _GUICtrlListBox_GetCurSel($ListofApps)
                _GUICtrlListBox_DeleteString($ListofApps, $iSel)
                $Count1 = $Count + 1
            EndIf
        EndIf
        If $button = $moveleftbtn1 Then
            $leftmoveitem = GUICtrlRead($AppsAdded)
            If StringStripWS($leftmoveitem, 8) Then
                ConsoleWrite($leftmoveitem & @CRLF)
                GUICtrlSetData($ListofApps, $leftmoveitem)
                $iSel = _GUICtrlListBox_GetCurSel($AppsAdded)
                _GUICtrlListBox_DeleteString($AppsAdded, $iSel)
                $Count1 = $Count + 1
            EndIf
        EndIf
    WEnd
EndFunc   ;==>Selectapps

:unsure:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You would have to get the count of items, then do a For/Next loop getting each item by index. That would be easy for you to convert to a function like "_GuiCtrlListBox_GetItemArray()".

:unsure:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...