Nothing2Lose 0 Posted September 21, 2010 Hi, How can i switch an edit control to a listbox control (one item per line) and the reverse??? I don't want to insert per item, it takes so much time... @@ Thanks! Share this post Link to post Share on other sites
smashly 12 Posted September 21, 2010 Hi, not sure if this is what you mean, but here goes from Edit To List one word per line in the listbox#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> Global $sText = "Some test text" & @CRLF & "Some More test Text" & @CRLF & "And here's some more test text" Global $hGui, $iEdit, $iListBox, $iButton, $iMsg $hGui = GUICreate("", 500, 400) $iEdit = GUICtrlCreateEdit($sText, 5, 5, 490, 365) $iListBox = GUICtrlCreateList("", 145, 5, 200, 365, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) $iButton = GUICtrlCreateButton("Show List", 210, 375, 80, 20) GUISetState(@SW_SHOW, $hGui) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iButton If GUICtrlRead($iButton) = "Show List" Then GUICtrlSetData($iButton, "Show Edit") GUICtrlSetState($iEdit, $GUI_HIDE) GUICtrlSetState($iListBox, $GUI_SHOW) GUICtrlSetData($iListBox, "") GUICtrlSetData($iListBox, StringReplace(StringReplace(StringStripCR(_GUICtrlEdit_GetText($iEdit)), @LF, "|"), " ", "|")) Else GUICtrlSetData($iButton, "Show List") GUICtrlSetState($iEdit, $GUI_SHOW) GUICtrlSetState($iListBox, $GUI_HIDE) EndIf EndSwitch WEnd Share this post Link to post Share on other sites
seandisanti 6 Posted September 21, 2010 (edited) Hi, How can i switch an edit control to a listbox control (one item per line) and the reverse??? I don't want to insert per item, it takes so much time... @@ Thanks! $tmp = StringSplit(ControlGetText($gui,$editcontrol),@CRLF) If Not @error Then _GUICtrlListBox_BeginUpdate($hListBox) For $i = 1 to $tmp[0] _GUICtrlListBox_AddString($hListBox,$tmp[$i] Next GUICtrlListBox_EndUpdate($hListBox) assuming you mean you want to populate a list with the line by line contents of an edit box ***edit*** P.S. didn't list the required #includes because i'm lazy, sorry Edited September 21, 2010 by cameronsdad Share this post Link to post Share on other sites
Nothing2Lose 0 Posted September 22, 2010 Hi, not sure if this is what you mean, but here goes from Edit To List one word per line in the listbox#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> Global $sText = "Some test text" & @CRLF & "Some More test Text" & @CRLF & "And here's some more test text" Global $hGui, $iEdit, $iListBox, $iButton, $iMsg $hGui = GUICreate("", 500, 400) $iEdit = GUICtrlCreateEdit($sText, 5, 5, 490, 365) $iListBox = GUICtrlCreateList("", 145, 5, 200, 365, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetState(-1, $GUI_HIDE) $iButton = GUICtrlCreateButton("Show List", 210, 375, 80, 20) GUISetState(@SW_SHOW, $hGui) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iButton If GUICtrlRead($iButton) = "Show List" Then GUICtrlSetData($iButton, "Show Edit") GUICtrlSetState($iEdit, $GUI_HIDE) GUICtrlSetState($iListBox, $GUI_SHOW) GUICtrlSetData($iListBox, "") GUICtrlSetData($iListBox, StringReplace(StringReplace(StringStripCR(_GUICtrlEdit_GetText($iEdit)), @LF, "|"), " ", "|")) Else GUICtrlSetData($iButton, "Show List") GUICtrlSetState($iEdit, $GUI_SHOW) GUICtrlSetState($iListBox, $GUI_HIDE) EndIf EndSwitch WEnd What about List To Edit??? Share this post Link to post Share on other sites
smashly 12 Posted September 22, 2010 (edited) What about List To Edit??? Problem is the list is one word per line. How would I know what words words make a sentence. I mean if I filled a list box with single words the the only thing that tells me the end of a sentence is a fullstop.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #Include <GuiListBox.au3> Global $sText = "Some|test|text.|Some|More|test|Text.|But|wait|here's|some|more|test|text." Global $hGui, $iEdit, $iListBox, $iButton, $iMsg, $sTmp, $sTxt $hGui = GUICreate("", 500, 400) $iEdit = GUICtrlCreateEdit("", 5, 5, 490, 365) GUICtrlSetState(-1, $GUI_HIDE) $iListBox = GUICtrlCreateList("", 145, 5, 200, 365, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetData(-1, $sText) $iButton = GUICtrlCreateButton("Show Edit", 210, 375, 80, 20) GUISetState(@SW_SHOW, $hGui) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iButton If GUICtrlRead($iButton) = "Show Edit" Then GUICtrlSetData($iButton, "Show List") GUICtrlSetState($iEdit, $GUI_SHOW) GUICtrlSetState($iListBox, $GUI_HIDE) GUICtrlSetData($iEdit, "") For $i = 0 To _GUICtrlListBox_GetCount($iListBox) -1 $sTmp = _GUICtrlListBox_GetText($iListBox, $i) If StringRight($sTmp, 1) = "." Then $sTxt &= $sTmp & @CRLF Else $sTxt &= $sTmp & " " EndIf Next GUICtrlSetData($iEdit, $sTxt) Else GUICtrlSetData($iButton, "Show Edit") GUICtrlSetState($iEdit, $GUI_HIDE) GUICtrlSetState($iListBox, $GUI_SHOW) EndIf EndSwitch WEnd If you explained better what your trying to accomplish then, maybe there's a better solution. Edited September 22, 2010 by smashly Share this post Link to post Share on other sites
Nothing2Lose 0 Posted September 22, 2010 Problem is the list is one word per line. How would I know what words words make a sentence. I mean if I filled a list box with single words the the only thing that tells me the end of a sentence is a fullstop.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #Include <GuiListBox.au3> Global $sText = "Some|test|text.|Some|More|test|Text.|But|wait|here's|some|more|test|text." Global $hGui, $iEdit, $iListBox, $iButton, $iMsg, $sTmp, $sTxt $hGui = GUICreate("", 500, 400) $iEdit = GUICtrlCreateEdit("", 5, 5, 490, 365) GUICtrlSetState(-1, $GUI_HIDE) $iListBox = GUICtrlCreateList("", 145, 5, 200, 365, BitOR($WS_BORDER, $WS_VSCROLL)) GUICtrlSetData(-1, $sText) $iButton = GUICtrlCreateButton("Show Edit", 210, 375, 80, 20) GUISetState(@SW_SHOW, $hGui) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iButton If GUICtrlRead($iButton) = "Show Edit" Then GUICtrlSetData($iButton, "Show List") GUICtrlSetState($iEdit, $GUI_SHOW) GUICtrlSetState($iListBox, $GUI_HIDE) GUICtrlSetData($iEdit, "") [b]For $i = 0 To [i]_GUICtrlListBox_GetCount($iListBox)[/i] -1[/b] $sTmp = _GUICtrlListBox_GetText($iListBox, $i) If StringRight($sTmp, 1) = "." Then $sTxt &= $sTmp & @CRLF Else $sTxt &= $sTmp & " " EndIf Next GUICtrlSetData($iEdit, $sTxt) Else GUICtrlSetData($iButton, "Show Edit") GUICtrlSetState($iEdit, $GUI_HIDE) GUICtrlSetState($iListBox, $GUI_SHOW) EndIf EndSwitch WEnd If you explained better what your trying to accomplish then, maybe there's a better solution. I use loop like your solution. But if the list has many items, it will take much time. This is my problem. Share this post Link to post Share on other sites
Nothing2Lose 0 Posted September 23, 2010 Does anyone have an idea??? Share this post Link to post Share on other sites