Jump to content

_GUICtrlListGetSelItemsText


 Share

Recommended Posts

Below I posted the code from the help file because I butchered mine up so bad. I want to get multiple items from a listbox and display them to an input box separated by comma's. All I can get is the last selected item to show up.

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

Opt ('MustDeclareVars', 1)

Dim $msg, $ret
Dim $listbox, $button, $label, $i, $input

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

$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
$input = guictrlcreateinput("",45,210,200,23)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            $ret = _GUICtrlListGetSelItemsText ($listbox)
            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItemsText")
            Else
                For $i = 1 To $ret[0]
                   ;MsgBox(0, "Selected", $ret[$i])
                    GUICtrlSetData(5,$ret[$i])
                Next
            EndIf
    EndSelect
WEnd
Link to comment
Share on other sites

Because Guictrlsetdata deletes all old data and then sets the new data, thus you must either make another variable and set all the data to it using an $variable &= $ret[$i] & "," or Just do a Guictrlsetdata($input,Guictrlread($input) & $ret[$i] & ",") both will result in a comma at the end so you can do like a stringtrimright to get rid of it

Link to comment
Share on other sites

That's right. Here is your code with some changes

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

Opt ('MustDeclareVars', 1)

Dim $msg, $ret
Dim $listbox, $button, $label, $i, $input

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

$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
$input = guictrlcreateinput("",45,210,200,23);<-----
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            $ret = _GUICtrlListGetSelItemsText ($listbox)
            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItemsText")
            Else
        $fil = ''
                For $i = 1 To $ret[0]
                   $fill = $fill & $ret[$i] & ','
                Next
        GUICtrlSetData($input,$fill]);<--Edited this line 
            EndIf
    EndSelect
WEnd
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

maybe...

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

Opt ('MustDeclareVars', 1)

Dim $msg, $ret
Dim $listbox, $button, $label, $i, $input

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

$listbox = GUICtrlCreateList("", 125, 40, 180, 120, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $LBS_MULTIPLESEL))
GUICtrlSetData($listbox, "test1|more testing|even more testing|demo|")
$button = GUICtrlCreateButton("Get Selected", 150, 160, 120, 40)
$input = guictrlcreateinput("",45,210,200,23)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            $ret = _GUICtrlListGetSelItemsText ($listbox)
            If (Not IsArray($ret)) Then
                MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItemsText")
            Else
                For $i = 1 To $ret[0]
                   ;MsgBox(0, "Selected", $ret[$i])
                    GUICtrlSetData(5,$ret[$i] & ", ", 1)
                Next
            EndIf
    EndSelect
WEnd

.... ah... a little slow, but i just changed one line

GUICtrlSetData(5,$ret[$i] & ", ", 1)

8)

Edited by Valuater

NEWHeader1.png

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