Jump to content
Sign in to follow this  

Simple list - deleting & loading item

Recommended Posts


let's say I have:

$scriptsList = GUICtrlCreateList("", 24, 64, 121, 60, BitOR($LBS_SORT, $WS_HSCROLL, $WS_VSCROLL))
$scriptsLoad = GUICtrlCreateButton("Load", 24, 141, 57, 20, $WS_GROUP)
$scriptsDel = GUICtrlCreateButton("Delete", 24, 125, 57, 15, $WS_GROUP)

Then I want to make it possible for user to load (.ini) file then it's inserted into list and he can also press delete if want to.

I already found a way for load but it's working badly (adds item double instead of one):

Case $nMsg = $scriptsLoad
                GUICtrlSetData ( $scriptsList, listSave("My gui window", $scriptsList)&"|"&FileOpenDialog ( "Select script", @ScriptDir, "Script file (*.ini)", 1))

Func listSave($windowName, $listName)
        Local $hLB = ControlGetHandle($windowName, "", $listName)
        Local $iCnt = _GUICtrlListBox_GetCount($hLB)
        Local $sMsg = ""
        For $n = 0 To $iCnt - 1
            $sMsg &= _GUICtrlListBox_GetText($hLB, $n) & "|"
        return $sMsg

could you show me how to make work delete and load functions?

thanks in advance!

Share this post

Link to post
Share on other sites

Here is one for you.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#Include <GuiListView.au3>

Dim $avarray

If FileExists(@ScriptDir&"\test.ini") Then

For $i=1 To 100
    FileWrite(@ScriptDir&"\test.ini",$i & @CRLF)

$Form1 = GUICreate("TEST LISTVIEW", 633, 354, 261, 161)
$ListView1 = GUICtrlCreateListView("|" & "|", 88, 56, 441, 193)

$Button1 = GUICtrlCreateButton("Load", 104, 288, 121, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Delete Item", 376, 288, 129, 25, $WS_GROUP)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1

            For $i=1 To $avarray[0]


Case $Button2
    _GUICtrlListView_DeleteItemsSelected($ListView1) ;deleting selected item


func _set()
    For $i=1 To $avarray[0]

    EndFunc; <=> _set()

[size="5"] [/size]

Share this post

Link to post
Share on other sites

How you best do this depends on a few things

Is there multiple sections in the INI? Do you want only the values in your list or the Key and Value? Do you want everything to display in the list including the section names?

If you want Keys and Values then I suggest that you switch to a ListView control. Easier to do that now than it is later.

If you only have one section the you will want IniReadSection() then populate the control from the resultant array.

If It has multiple sections then you do basicly the same except you pre-process it with IniReadSectionNames() and then use 2 (nested) loops to populate from the arrays.

If it's only a flat file with an Ini layout and no section names then it's another whole ball of wax. There I would probably go with StringRegExp() setting the flag to 3


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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