Sign in to follow this  
Followers 0
Stalker0

Selecting Multiple Items in a List

4 posts in this topic

First of all, let me say that I've only been using autoit for a few weeks now and have picked it up slowly. However, this community has been wonderful, you guys have helped me out with all of my newb questions and I appreciate it.

I'm creating a new GUI that involves a list or listview. I have a series of numbers in one list. I need to be able to select a portion of them, and with a button press move them over into another list. Is this possible with autoit gui controls?

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

I could have sworn I replied to this.. Anyway:

[ edit ]

oohh http://www.autoitscript.com/forum/index.php?showtopic=55008

[ /edit]

#include <GUIConstants.au3>
#include <GuiList.au3>

$Form1 = GUICreate("Choices Dialog", 353, 263, 215, 152)
GUISetIcon("D:07.ico")
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 201, $LBS_MULTIPLESEL)
GUICtrlSetData(-1, "Item1|Item2|Item3|Item4|Item5")
$moveright = GUICtrlCreateButton(">", 156, 15, 30, 25, 0)
$moveleft = GUICtrlCreateButton("<", 157, 81, 31, 25, 0)
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 201,$LBS_MULTIPLESEL)
GUICtrlCreateButton("&OK", 96, 225, 75, 25, $BS_DEFPUSHBUTTON)
GUICtrlCreateButton("&Cancel", 184, 225, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $moveright
            $index1=_GUICtrlListGetSelItems ( $listbox1 )
            If IsArray($index1) Then
                For $i=1 to UBound($index1)-1

                    $Text= _GUICtrlListGetText ( $listbox1, $index1[$i])
                    _GUICtrlListDeleteItem ( $listbox1,$index1[$i] )
                    _GUICtrlListAddItem ($listbox2,$Text)
                Next
            EndIf
        case $moveleft
            $index1=_GUICtrlListGetSelItems ( $listbox2 )
            GUICtrlSetState($listbox1,$GUI_FOCUS)
            If IsArray($index1) Then
                For $i=1 to UBound($index1)-1
                    $Text= _GUICtrlListGetText ( $listbox2, $index1[$i])
                    _GUICtrlListDeleteItem ( $listbox2,$index1[$i] )
                    _GUICtrlListAddItem ($listbox1,$Text)
                Next
            EndIf
    EndSwitch
WEnd

it has some troubles when selecting multiple items, but I leave that to you :)

Edited by Nahuel

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

have only been learning Autoit for a few hour and I find it is very interesting. Iwas able to get the multi select list boxes to work with corrections below.

#include <GUIConstants.au3>
#include <GuiList.au3>

$Form1 = GUICreate("Choices Dialog", 353, 263, 215, 152)
GUISetIcon("D:07.ico")
$ListBox1 = GUICtrlCreateList("", 8, 8, 137, 201, $LBS_MULTIPLESEL)
GUICtrlSetData(-1, "Item 1|Item 2|Item 3|Item 4|Item 5")
$moveright = GUICtrlCreateButton(">", 156, 15, 30, 25, 0)
$moveleft = GUICtrlCreateButton("<", 157, 81, 31, 25, 0)
$ListBox2 = GUICtrlCreateList("", 200, 8, 137, 201,$LBS_MULTIPLESEL)
GUICtrlCreateButton("&OK", 96, 225, 75, 25, $BS_DEFPUSHBUTTON)
GUICtrlCreateButton("&Cancel", 184, 225, 75, 25, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $moveright
            $index1=_GUICtrlListGetSelItems ( $listbox1 )
            If IsArray($index1) Then
                For $i= 1 to $index1[0]
                    $Text= _GUICtrlListGetText ( $listbox1, $index1[$i])
                    _GUICtrlListAddItem ($listbox2,$Text)
                Next
                For $i= $index1[0] to 1 step -1
                    $Text= _GUICtrlListGetText ( $listbox1, $index1[$i])
                    _GUICtrlListDeleteItem ( $listbox1,$index1[$i] )
                Next
            EndIf
        case $moveleft
            $index1=_GUICtrlListGetSelItems ( $listbox2 )
            GUICtrlSetState($listbox1,$GUI_FOCUS)
            If IsArray($index1) Then
                For $i=1 to $index1[0]
                    $Text= _GUICtrlListGetText ( $listbox2, $index1[$i])
                    _GUICtrlListAddItem ($listbox1,$Text)
                Next
                For $i= $index1[0] to 1 step -1
                    $Text= _GUICtrlListGetText ( $listbox2, $index1[$i])
                    _GUICtrlListDeleteItem ( $listbox2,$index1[$i] )
                Next
            EndIf
    EndSwitch
WEnd

Have fun with it.

Edited by ChrisMCDataSys

Share this post


Link to post
Share on other sites

Very good! <_<

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