Jump to content

find slected item in listbox


lilx
 Share

Recommended Posts

Hello,

I am tryin to make a gui to be used to add or delete value’s from a array. Most of it Is already done but know I have the following problem.

I am tryin to figure out what command is used to know what the user have selected in my listbox. So I can find the array number en delete that array number only.

Example:

the user press ”pinoccio” on my listbox and the press on the button “delete selected”. It will delete “pinoccio” in my array and leave “kabouter plop|clown|banaan” in my array.

I currently have this for script

#include <GUIConstantsEx.au3>
#include <ListboxConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>



Opt('MustDeclareVars', 1)


    Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio " , "|")
    Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput
    
    $FLgui = GUICreate("Filter List", 400, 385)

    $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25)
    $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25)
    $FLlist = GUICtrlCreateList("", 5, 5, 300, 350)
    $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20)     ; will not accept drag&drop files
    
    ;GUICtrlSetLimit($FLlist, 200)  ; to limit horizontal scrolling
    For $i = 1 to $MESSAGE[0]
    GUICtrlSetData($FLlist, $MESSAGE[$i])
    Next

    GUISetState()
    While 1 
        $FLmsg = GUIGetMsg()
        Select
            Case $FLmsg = $GUI_EVENT_CLOSE
                Exit
            Case $FLmsg = $FLadd
                _ArrayAdd($MESSAGE, GUICtrlRead($FLinput))
                _GUICtrlListBox_BeginUpdate($FLlist)
                _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput))
                _GUICtrlListBox_UpdateHScroll($FLlist)
                _GUICtrlListBox_EndUpdate($FLlist)
                $MESSAGE[0] = $MESSAGE[0] + 1 
                ;_ArrayDisplay($MESSAGE, "Updated Array")
            Case $FLmsg = $FLclear

        EndSelect
    WEnd
Edited by lilx
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <ListboxConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>



Opt('MustDeclareVars', 1)


    Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio " , "|")
    Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput, $Selected
   
    $FLgui = GUICreate("Filter List", 400, 385)

    $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25)
    $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25)
    $FLlist = GUICtrlCreateList("", 5, 5, 300, 350)
    $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20)  ; will not accept drag&drop files
   
   ;GUICtrlSetLimit($FLlist, 200) ; to limit horizontal scrolling
    For $i = 1 to $MESSAGE[0]
    GUICtrlSetData($FLlist, $MESSAGE[$i])
    Next

    GUISetState()
    While 1
        $FLmsg = GUIGetMsg()
        Select
            Case $FLmsg = $GUI_EVENT_CLOSE
                Exit
            Case $FLmsg = $FLadd
                _ArrayAdd($MESSAGE, GUICtrlRead($FLinput))
                _GUICtrlListBox_BeginUpdate($FLlist)
                _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput))
                _GUICtrlListBox_UpdateHScroll($FLlist)
                _GUICtrlListBox_EndUpdate($FLlist)
                $MESSAGE[0] = $MESSAGE[0] + 1
               ;_ArrayDisplay($MESSAGE, "Updated Array")
            Case $FLmsg = $FLclear
               $Selected = _GUICtrlListBox_GetCurSel($FLlist)
               _GUICtrlListBox_DeleteString($FLlist, $selected)
        EndSelect
    WEnd

Link to comment
Share on other sites

aha thank you very much. i went true almost all _GUICtrlListBox and just couldn't see/find it :o

now just deleted it out of my array and done :D, but that i can do myself :D

Edited by lilx
Link to comment
Share on other sites

btw a other question outside the topic subject, but question isn't serious enough to start new topic.

i am using for this module string split.

i know that a string have a maximum string length of 2147483647 characters but AutoIt script can only have 4095 characters.

is this maxium the same for stringsplit? or is the maximum of stringsplit less?

Link to comment
Share on other sites

No probs

I don't think it works for multiple selections though, so if you want that use darams one, It works for more than 1 selecion.

MDiesel

to avoid problems is it possible then to limit the selection to one at a time?

Link to comment
Share on other sites

well i thought i would have no problems with the array stuff but i have it :D,

i am getting at the arraysearch a -1 return. meaning my variable isn't a array wich i don't get...

#include <GUIConstantsEx.au3>
#include <ListboxConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>



Opt('MustDeclareVars', 1)


    Local $MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio" , "|")
    Local $FLadd, $FLclear, $FLlist, $FLmsg, $FLgui, $FLinput, $FLindex, $FLtext, $FLpos
    
    $FLgui = GUICreate("Filter List", 400, 385)

    $FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25)
    $FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25)
    $FLlist = GUICtrlCreateList("", 5, 5, 300, 350)
    $FLinput = GUICtrlCreateInput("", 5, 355, 300, 20)     ; will not accept drag&drop files
    
    ;GUICtrlSetLimit($FLlist, 200)  ; to limit horizontal scrolling
    For $i = 1 to $MESSAGE[0]
    GUICtrlSetData($FLlist, $MESSAGE[$i])
    Next

    GUISetState()
    While 1 
        $FLmsg = GUIGetMsg()
        Select
            Case $FLmsg = $GUI_EVENT_CLOSE
                Exit
            Case $FLmsg = $FLadd
                _ArrayAdd($MESSAGE, GUICtrlRead($FLinput))
                _GUICtrlListBox_BeginUpdate($FLlist)
                _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput))
                _GUICtrlListBox_UpdateHScroll($FLlist)
                _GUICtrlListBox_EndUpdate($FLlist)
                $MESSAGE[0] = $MESSAGE[0] + 1 
                _ArrayDisplay($MESSAGE, "Updated Array")
            Case $FLmsg = $FLclear
                $FLindex = _GUICtrlListBox_GetCurSel($FLlist)           
                $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex)    
                MsgBox ( 48, "test1", $FLtext )
                $FLpos = _ArraySearch($FLlist, $FLtext, 0, 0, 0, 1)     ; getting -1 error here?
                MsgBox ( 48, "test2", $FLpos )
                _ArrayDelete($FLlist, $FLpos)                           
                $MESSAGE[0] = $MESSAGE[0] - 1                           
               _GUICtrlListBox_DeleteString($FLlist, $FLindex)  
               _ArrayDisplay($MESSAGE, "Updated Array")
        EndSelect
    WEnd
Link to comment
Share on other sites

you had a mix up between your arrays, study this code, and learn from your mistakes.....

i have only updated your delete func, youll need to change your add func to make it work....

you were searching in the array $FLlist whcih is the listbox, not the array that contains the data $MESSAGE

#include <GUIConstantsEx.au3>
#include <ListboxConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>



$MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio", "|")


$FLgui = GUICreate("Filter List", 400, 385)

$FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25)
$FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25)
$FLlist = GUICtrlCreateList("", 5, 5, 300, 350)
$FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files

;GUICtrlSetLimit($FLlist, 200)  ; to limit horizontal scrolling
For $i = 1 To $MESSAGE[0]
    GUICtrlSetData($FLlist, $MESSAGE[$i])
Next

GUISetState()
While 1
    $FLmsg = GUIGetMsg()
    Select
        Case $FLmsg = $GUI_EVENT_CLOSE
            Exit
        Case $FLmsg = $FLadd
            _ArrayAdd($MESSAGE, GUICtrlRead($FLinput))
            _GUICtrlListBox_BeginUpdate($FLlist)
            _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput))
            _GUICtrlListBox_UpdateHScroll($FLlist)
            _GUICtrlListBox_EndUpdate($FLlist)
            $MESSAGE[0] = $MESSAGE[0] + 1
            _ArrayDisplay($MESSAGE, "Updated Array")
        Case $FLmsg = $FLclear
            $FLindex = _GUICtrlListBox_GetCurSel($FLlist)
            $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex)
            $FLpos = _ArraySearch($MESSAGE, $FLtext, 1, 0, 0, 0, 1, 0)
            ConsoleWrite("pos " & $FLpos & @LF)
            _ArrayDelete($MESSAGE, $FLpos)
            $MESSAGE[0] = UBound($MESSAGE) - 1
            _GUICtrlListBox_DeleteString($FLlist, $FLindex)
            _ArrayDisplay($MESSAGE, "After Deletion")
    EndSelect
WEnd
Edited by Aceguy
Link to comment
Share on other sites

you had a mix up between your arrays, study this code, and learn from your mistakes.....

i have only updated your delete func, youll need to change your add func to make it work....

you were searching in the array $FLlist whcih is the listbox, not the array that contains the data $MESSAGE

#include <GUIConstantsEx.au3>
#include <ListboxConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>



$MESSAGE = StringSplit("kabouter plop|clown|banaan|pinoccio", "|")


$FLgui = GUICreate("Filter List", 400, 385)

$FLadd = GUICtrlCreateButton("Add", 310, 352, 85, 25)
$FLclear = GUICtrlCreateButton("Delete Selected", 310, 6, 85, 25)
$FLlist = GUICtrlCreateList("", 5, 5, 300, 350)
$FLinput = GUICtrlCreateInput("", 5, 355, 300, 20) ; will not accept drag&drop files

;GUICtrlSetLimit($FLlist, 200)  ; to limit horizontal scrolling
For $i = 1 To $MESSAGE[0]
    GUICtrlSetData($FLlist, $MESSAGE[$i])
Next

GUISetState()
While 1
    $FLmsg = GUIGetMsg()
    Select
        Case $FLmsg = $GUI_EVENT_CLOSE
            Exit
        Case $FLmsg = $FLadd
            _ArrayAdd($MESSAGE, GUICtrlRead($FLinput))
            _GUICtrlListBox_BeginUpdate($FLlist)
            _GUICtrlListBox_AddString($FLlist, GUICtrlRead($FLinput))
            _GUICtrlListBox_UpdateHScroll($FLlist)
            _GUICtrlListBox_EndUpdate($FLlist)
            $MESSAGE[0] = $MESSAGE[0] + 1
            _ArrayDisplay($MESSAGE, "Updated Array")
        Case $FLmsg = $FLclear
            $FLindex = _GUICtrlListBox_GetCurSel($FLlist)
            $FLtext = _GUICtrlListBox_GetText($FLlist, $FLindex)
            $FLpos = _ArraySearch($MESSAGE, $FLtext, 1, 0, 0, 0, 1, 0)
            ConsoleWrite("pos " & $FLpos & @LF)
            _ArrayDelete($MESSAGE, $FLpos)
            $MESSAGE[0] = UBound($MESSAGE) - 1
            _GUICtrlListBox_DeleteString($FLlist, $FLindex)
            _ArrayDisplay($MESSAGE, "After Deletion")
    EndSelect
WEnd
hi, and thank you for the responce, i indeed sometimes make those mistakes. but offent when i am working the code or the problem for longer time you see things over head. and thats why i posted it so a pair of fresh eyes can take a look at it :D
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...