Jump to content
Sign in to follow this  

[solved] guictrlcreatelist can I access list items?

Recommended Posts


I got to playing with guictrlcreatelist and didn't know how to access cells of the list.

I need to access cells of the list to check against cells of the list and or remove cells.

before asking for help I found a way to do it by storing a string to represent contents of the list, but shouldn't the list already know what's inside it? there must be a better way.

Here is what I wrote so far, and it works. The complete script uses Melba23's _RecFileListToArray which is the only udf I found that lets me drop my entire 'My Music' folder into my hotkey gui. Very nice udf thank you Melba23.

#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListboxConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#include <Misc.au3>

global $dragdropinclude= "*.wma;*.ogg;*.flac;*.mp3;*.wav;*.mid;*.midi"
showsettings(100, 100,  610, 430, "settings")

func showsettings($winx, $winy, $winw, $winh, $caption)
    $settingswindow= GUICreate($caption, $winw, $winh, $winx, $winy);make window
    $settingdescription= GUICtrlCreateEdit("", 50, 20, 500, 80);field for descriptions of fields
    GuiCtrlSendMsg($settingdescription, $EM_SETREADONLY, 1, 0);don't allow users to modify $settingdescription field
    $tab= GUICtrlCreateTab(5, 120, 600, 200)
    ;$tab1= GUICtrlCreateTabItem("general")
    ;loaddialogtab(@ScriptDir&"\system\settings dialog\tab1 dialog control map.txt", $controls, $controlsonpage);not needed in example
    $tab2= GUICtrlCreateTabItem("drag n drop")
    GUICtrlSetState($tab2, $gui_show)
    ;setup tab2 controls and labels
    GUICtrlCreateLabel("Only include these extensions:", 33, 156)
    GUICtrlCreateLabel("add extensions to list", 190, 176)
    $inputinclude= GUICtrlCreateInput("", 205, 195, 100, 20)
    $buttoninclude= GUICtrlCreateButton("<", 190, 195, 15, 20)
    $buttonincluderemove= GUICtrlCreateButton("remove", 33, 266, 100, 20)
    $listinclude= GUICtrlCreateList("", 33, 176, 150, 90, $LBS_NOTIFY+$WS_VSCROLL)
    ;load dragdropinclude to $listinclude
    $extarray= StringSplit($dragdropinclude, ";")
    $stringincludelist= "";this string is used to reflect contents of $listinclude
    for $i= 1 to $extarray[0]
        $stringincludelist= $stringincludelist&$extarray[$i]&";"
        GUICtrlSetData($listinclude, $extarray[$i]&"|")
    $stringincludelist= stringleft($stringincludelist, StringLen($stringincludelist)-1);remove trailing ';' from $stringincludelist
    GUICtrlCreateLabel("exclude these extensions:", 330, 156)
    $listexclude= GUICtrlCreateList("", 330, 176, 150, 90, $LBS_NOTIFY+$WS_VSCROLL);undeveloped

        $controlfocus= ControlGetFocus($settingswindow)
        $settingsmsg= GUIGetMsg($settingswindow)

        if $settingsmsg= $buttoninclude or (_IsPressed("0d") and ControlGetFocus($settingswindow)= "edit2") Then
            $temp= GUICtrlRead($inputinclude);read ext from input field
            if $temp<> "" then;inserting null cleared my list, and that's no good for this
                $extarray= StringSplit($stringincludelist, ";")
                $addtolist= 1
                for $i= 1 to $extarray[0];look for extension already in list before adding
                    if $temp= $extarray[$i] Then;on match don't add extension to list
                        $addtolist= 0;
                if $addtolist= 1 then
                    $stringincludelist= $stringincludelist&";"&$temp;append ext to include list string
                    GUICtrlSetData($listinclude, $temp&"|");append ext to $listinclude

        if $settingsmsg= $buttonincluderemove Then
            $extarray= StringSplit($stringincludelist, ";")
            $temp= GUICtrlRead($listinclude)
            for $i= 1 to $extarray[0];loop through array to find target to remove
                if $temp= $extarray[$i] then;if target found remove extension from list
                    $stringincludelist= "";clear $stringincludelist
                    guictrlsetdata($listinclude, "");clear $listinclude
                    for $ii= $i to $extarray[0]-1;shift array left at target
                        $extarray[$ii]= $extarray[$ii+1]
                    $extarray[0]= $extarray[0]-1
                    for $ii= 1 to $extarray[0];remake $stringincludelist and $listinclude
                        $stringincludelist= $stringincludelist&$extarray[$ii]&";"
                        GUICtrlSetData($listinclude, $extarray[$ii]&"|")
                    $stringincludelist= stringleft($stringincludelist, StringLen($stringincludelist)-1);remove trailing ';'
        ;ConsoleWrite(ControlGetFocus($settingswindow));tool to output whatever ControlGetFocus() returns
        ;if $controlfocus<> ControlGetFocus($settingswindow) Then
        if _IsPressed("01") then
            switch $controlfocus
            case "Listbox1"
                GUICtrlSetData($settingdescription, "click 'remove' button to remove "&GUICtrlRead($listinclude)&" from include list.")
                GUICtrlSetData($buttonincluderemove, "remove "&GUICtrlRead($listinclude))
            case "Listbox2"
                GUICtrlSetData($settingdescription, "under construction; undeveloped")
            case "edit2"
                GUICtrlSetData($settingdescription, "type a new extension to add to list"&@crlf&"remember to use wildcards. Example: *.ext"&@crlf&"then press ENTER")
    Until $settingsmsg= $gui_event_close
    $dragdropinclude= $stringincludelist
    MsgBox(0, "$dragdropinclude file string =", $dragdropinclude)
EndFunc; showsettings()
Edited by songersoft

Share this post

Link to post
Share on other sites


Thank you for the compliments. :)

Take a look at the GuiListBox UDF - _GUICtrlListBox_DeleteString, _GUICtrlListBox_FindString and _GUICtrlListBox_AddString look like the functions you might need. ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


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