VAADAdmin Posted December 28, 2006 Share Posted December 28, 2006 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 More sharing options...
Thatsgreat2345 Posted December 28, 2006 Share Posted December 28, 2006 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 More sharing options...
martin Posted December 28, 2006 Share Posted December 28, 2006 (edited) 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 December 28, 2006 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 More sharing options...
Valuater Posted December 28, 2006 Share Posted December 28, 2006 (edited) 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 December 28, 2006 by Valuater Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted December 28, 2006 Share Posted December 28, 2006 (edited) O my goodness i didn't know that parameter with GUictrlsetData xD Edited December 28, 2006 by Thatsgreat2345 Link to comment Share on other sites More sharing options...
Valuater Posted December 28, 2006 Share Posted December 28, 2006 this actually will return a better result than my one liner GUICtrlSetData($input,StringTrimRight($fill,1)) because it removes the last comma 8) Link to comment Share on other sites More sharing options...
VAADAdmin Posted December 28, 2006 Author Share Posted December 28, 2006 Thank you all for your help and the quick response. I now have it working pretty well. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now