Jump to content

Moving items from one list box to another


Recommended Posts

I am trying to create a script that moves items from one list box to the next. Now.. my current script is functional in adding items from list 1 to list 2 and vice versa.. the problem I am having is figuring out how to actually remove an item from the old list once it is moved.

here is my current code.

$container1 = ("left1|left2|left3|left4")
$container2 = ("right1|right2|right3|right4")

GUICreate("List Box Move", 460,290)

    $list1 = GuiCtrlCreateList("", 10, 10, 200, 290)
    GuiCtrlSetData($list1, $container1, "")
    
    $list2 = GuiCtrlCreateList("", 250, 10, 200, 290)
    GuiCtrlSetData($list2, $container2, "")

    $moverightbtn1 = GuiCtrlCreateButton("<<",220,100,20,20)
    $moveleftbtn1 = GuiCtrlCreateButton(">>",220,130,20,20)
    $exitbtn1 = GuiCtrlCreateButton("X",220,160,20,20)

GUISetState()

While 1
    
    $button = guigetmsg()
    
    If $button = $exitbtn1 Then Exit

    if $button = $moverightbtn1 Then
        $rightmoveitem = GuiCtrlRead($list2)
        $container1 = ($container1 & ("|" & $rightmoveitem))
        
    ;clear list
        GuiCtrlSetdata($list1, "","")
    ;set new list
        GuiCtrlSetdata($list1, $container1, $rightmoveitem)
    EndIf
    
    if $button = $moveleftbtn1 Then
        $leftmoveitem = GuiCtrlRead($list1)
        $container2 = ($container2 & ("|" & $leftmoveitem))
        
    ;clear list
        GuiCtrlSetdata($list2, "","")
    ;set new list
        GuiCtrlSetdata($list2, $container2, $leftmoveitem)
    EndIf
    
WEnd
Link to comment
Share on other sites

You could use _GUICtrlListViewDeleteItem


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

I started working on it and I think I got it....

this seems to do the trick for those that want it :D

$container1 = ("left1|left2|left3|left4")
$container2 = ("right1|right2|right3|right4")

GUICreate("List Box Move", 460,290)

    $list1 = GuiCtrlCreateList("", 10, 10, 200, 290)
    GuiCtrlSetData($list1, $container1, "")
    
    $list2 = GuiCtrlCreateList("", 250, 10, 200, 290)
    GuiCtrlSetData($list2, $container2, "")

    $moverightbtn1 = GuiCtrlCreateButton("<<",220,100,20,20)
    $moveleftbtn1 = GuiCtrlCreateButton(">>",220,130,20,20)
    $exitbtn1 = GuiCtrlCreateButton("X",220,160,20,20)

GUISetState()

While 1
    
    $button = guigetmsg()
    
    If $button = $exitbtn1 Then Exit

    if $button = $moverightbtn1 Then
        
        If $container2 = ("") Then 
        Else
                
        $rightmoveitem = GuiCtrlRead($list2)
        $container1 = ($container1 & ("|" & $rightmoveitem))
        
    ;clear list
        GuiCtrlSetdata($list1, "","")
    ;set new list
        GuiCtrlSetdata($list1, $container1, $rightmoveitem)
    
    
    ;clear list
        GuiCtrlSetdata($list2, "","")
        
    ;reset line with |
        
        $container2 = StringReplace($container2, ("|" & $rightmoveitem), "")
        $container2 = StringStripws($container2,8)
        
    ;reset line with out |
        
        $container2 = StringReplace($container2, ($rightmoveitem), "")
        $container2 = StringStripws($container2,8)
        
    ;set new list
        GuiCtrlSetdata($list2, $container2,"")
            
        EndIf
    EndIf
    
    
    if $button = $moveleftbtn1 Then
        
        If $container1 = ("") Then 
        Else
        
        $leftmoveitem = GuiCtrlRead($list1)
        $container2 = ($container2 & ("|" & $leftmoveitem))
        
    ;clear list
        GuiCtrlSetdata($list2, "","")
    ;set new list
        GuiCtrlSetdata($list2, $container2, $leftmoveitem)
    
    
    ;clear list
        GuiCtrlSetdata($list1, "","")
        
    ;reset line with |
        
        $container1 = StringReplace($container1, ("|" & $leftmoveitem), "")
        $container1 = StringStripws($container1,8)
        
    ;reset line with out |
        
        $container1 = StringReplace($container1, ($leftmoveitem), "")
        $container1 = StringStripws($container1,8)
        
    ;set new list
        GuiCtrlSetdata($list1, $container1,"")
        
    EndIf
EndIf

WEnd
Edited by gleem
Link to comment
Share on other sites

or maybe the correct way

#Include <GuiList.au3>
#include <GuiConstants.au3>

$container1 = ("left1|left2|left3|left4")
$container2 = ("right1|right2|right3|right4")

GUICreate("List Box Move", 460, 290)

$list1 = GUICtrlCreateList("", 10, 10, 200, 290)

GUICtrlSetData($list1, $container1, "")

$list2 = GUICtrlCreateList("", 250, 10, 200, 290)
GUICtrlSetData($list2, $container2, "")

$moveleftbtn1 = GUICtrlCreateButton("<<", 220, 100, 20, 20)
$moverightbtn1 = GUICtrlCreateButton(">>", 220, 130, 20, 20)
$exitbtn1 = GUICtrlCreateButton("X", 220, 160, 20, 20)

GUISetState()

While 1
    
    $button = GUIGetMsg()
    
    If $button = $exitbtn1 Or $button = $GUI_EVENT_CLOSE Then Exit
    
    If $button = $moverightbtn1 Then
        If GUICtrlRead($list1) <> "" Then
        _GUICtrlListAddItem ($list2, GUICtrlRead($list1))
        _GUICtrlListDeleteItem($list1, _GUICtrlListSelectedIndex($list1))
        EndIf
    EndIf
    
    If $button = $moveleftbtn1 Then
        If GUICtrlRead($list2) <> "" Then
        _GUICtrlListAddItem ($list1, GUICtrlRead($list2))
        _GUICtrlListDeleteItem($list2, _GUICtrlListSelectedIndex($list2))
        EndIf
    EndIf
    
WEnd

even these were wrong

$moverightbtn1 = GuiCtrlCreateButton("<<",220,100,20,20)
    $moveleftbtn1 = GuiCtrlCreateButton(">>",220,130,20,20)

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

hehe.. I am still a newbie with it comes to programming... thank you Valuater for your input..

can you sort the items alphabetically with the _GUICtrlListAddItem?

I noitced with strings.. it does this automatically

Link to comment
Share on other sites

welcome...

sorted

#Include <GuiList.au3>
#include <GuiConstants.au3>

$container1 = ("left|coffee|milk|sugar")
$container2 = ("right|wrong|indifferent|justice")

GUICreate("List Box Move", 460, 290)

$list1 = GUICtrlCreateList("", 10, 10, 200, 290, $LBS_SORT)

GUICtrlSetData($list1, $container1, "")

$list2 = GUICtrlCreateList("", 250, 10, 200, 290, $LBS_SORT)
GUICtrlSetData($list2, $container2, "")

$moveleftbtn1 = GUICtrlCreateButton("<<", 218, 100, 24, 20)
$moverightbtn1 = GUICtrlCreateButton(">>", 218, 130, 24, 20)
$exitbtn1 = GUICtrlCreateButton("X", 218, 160, 24, 20)

GUISetState()

While 1
    
    $button = GUIGetMsg()
    
    If $button = $exitbtn1 Or $button = $GUI_EVENT_CLOSE Then Exit
    
    If $button = $moverightbtn1 Then
        If GUICtrlRead($list1) <> "" Then
        _GUICtrlListAddItem ($list2, GUICtrlRead($list1))
        _GUICtrlListDeleteItem($list1, _GUICtrlListSelectedIndex($list1))
        EndIf
    EndIf
    
    If $button = $moveleftbtn1 Then
        If GUICtrlRead($list2) <> "" Then
        _GUICtrlListAddItem ($list1, GUICtrlRead($list2))
        _GUICtrlListDeleteItem($list2, _GUICtrlListSelectedIndex($list2))
        EndIf
    EndIf
    
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 3 months later...

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...