Jump to content
Sign in to follow this  
Nothing2Lose

Listbox and Edit...

Recommended Posts

Nothing2Lose

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

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

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 by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites
Nothing2Lose

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

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.

#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 by smashly

Share this post


Link to post
Share on other sites
Nothing2Lose

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.

#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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.