Jump to content
Sign in to follow this  
Knight

Get all Items in List?

Recommended Posts

Knight

I am trying to get the text of all the items in a listbox and store it into an array. I have looked at all the standard functions and UDF's in the help menu, as well as searched the forums. I am either blind or overlooked something.

Is there any efficient way of doing this without having to select each item and record it into the array?

Thanks

-JKnight

Share this post


Link to post
Share on other sites
GaryFrost

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

opt('MustDeclareVars', 1)

Dim $msg, $ret
Dim $listbox, $label, $button, $x

GUICreate("ListBox Get Text Demo", 400, 250, -1, -1)

$listbox = GUICtrlCreateList("", 125, 40, 180, 120)
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get", 165, 180, 90, 25)
$label = GUICtrlCreateLabel("Item #", 150, 210, 120)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $listbox
            $ret = _GUICtrlListGetText ($listbox, _GUICtrlListSelectedIndex ($listbox))
            If ($ret == $LB_ERR) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetText")
            Else
                GUICtrlSetData($label, "Item : " & $ret)
            EndIf
        Case $msg = $button
            Dim $a_list
            For $x = 0 To _GUICtrlListCount ($listbox) - 1
                If Not IsArray($a_list) Then
                    Dim $a_list[1]
                Else
                    ReDim $a_list[UBound($a_list) + 1]
                EndIf
                $a_list[UBound($a_list) - 1] = _GUICtrlListGetText ($listbox, $x)
            Next
            For $x = 0 To UBound($a_list) - 1
                MsgBox(0, $x, $a_list[$x])
            Next
    EndSelect
WEnd

Edited by gafrost

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
Knight

Thank you very much gafrost. Ill try it out when I have time!

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  

×