Sign in to follow this  
Followers 0
Stalker0

Selecting Multiple Items in a List

5 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

Something like this?

#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 $index1[0]
                    $Text= _GUICtrlListGetText ( $listbox1, $index1[$i])
                    _GUICtrlListAddItem ($listbox2,$Text)
                    _GUICtrlListDeleteItem ( $listbox1,$index1[$i] )
                Next
            EndIf
        case $moveleft
            $index1=_GUICtrlListGetSelItems ( $listbox2 )
            If IsArray($index1) Then
                For $i=1 to $index1[0]
                    $Text= _GUICtrlListGetText ( $listbox2, $index1[$i])
                    _GUICtrlListAddItem ($listbox1,$Text)
                    _GUICtrlListDeleteItem ( $listbox2,$index1[$i] )
                Next
            EndIf
    EndSwitch
WEnd

It has some trouble when trying to move many items, but I leave that to you :)

Share this post


Link to post
Share on other sites

Thanks for the help. Yeah, my main problem is still with the multiple select function on a list.

Tell me, I know you can select multiple items with a listview. However, I haven't seen a command in the help menu that can take a selection in listview and convert it into an array that I can port over to another list or listview.

Also, I didn't see this style in the help menu, LBS_MULTIPLESEL, is there a larger list of styles somewhere?

Share this post


Link to post
Share on other sites

Thanks for the help. Yeah, my main problem is still with the multiple select function on a list.

No problem.

Tell me, I know you can select multiple items with a listview. However, I haven't seen a command in the help menu that can take a selection in listview and convert it into an array that I can port over to another list or listview.

Well.. you can do that. Shouldn't be that hard...

Also, I didn't see this style in the help menu, LBS_MULTIPLESEL, is there a larger list of styles somewhere?

Yeah, look for GUI Control Styles in help file.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

also in the beta help, Look at the UDFs

#include <GuiConstants.au3>
#include <GUIListBox.au3>

Opt('MustDeclareVars', 1)

$Debug_LB = False ; Check ClassName being passed to ListBox functions, set to True and use a handle to another control to see it work

Example_Internal()
Example_External()

Func Example_Internal()
    Local $hGUI, $hListBox

    ; Create GUI
    $hGUI = GUICreate("(Internal) List Box Get Sel Count", 400, 296)
    $hListBox = GUICtrlCreateList("", 2, 2, 396, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUISetState()

    ; Add strings
    _GUICtrlListBox_BeginUpdate ($hListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString ($hListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_EndUpdate ($hListBox)

    ; Select a few items
    _GUICtrlListBox_SetSel ($hListBox, 3)
    _GUICtrlListBox_SetSel ($hListBox, 4)
    _GUICtrlListBox_SetSel ($hListBox, 5)

    ; Show the item selection state
    MsgBox(4160, "Information", "Items Selected: " & _GUICtrlListBox_GetSelCount ($hListBox))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_Internal

Func Example_External()
    Local $hGUI, $hListBox

    ; Create GUI
    $hGUI = GUICreate("(External) List Box Get Sel Count", 400, 296)
    $hListBox = _GUICtrlListBox_Create ($hGUI, "", 2, 2, 396, 296, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL))
    GUISetState()

    ; Add strings
    _GUICtrlListBox_BeginUpdate ($hListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString ($hListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_EndUpdate ($hListBox)

    ; Select a few items
    _GUICtrlListBox_SetSel ($hListBox, 3)
    _GUICtrlListBox_SetSel ($hListBox, 4)
    _GUICtrlListBox_SetSel ($hListBox, 5)

    ; Show the item selection state
    MsgBox(4160, "Information", "Items Selected: " & _GUICtrlListBox_GetSelCount ($hListBox))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example_External
Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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