Sign in to follow this  
Followers 0
Ajdi

Simple list - deleting & loading item

3 posts in this topic

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):

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


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) & "|"
        Next
        return $sMsg
EndFunc

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
    FileDelete(@ScriptDir&"\test.ini")
    EndIf

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

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

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


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

            For $i=1 To $avarray[0]
        GUICtrlCreateListViewItem($avarray[$i],$ListView1)

Next

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




    EndSwitch
WEnd




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

    Next
    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


George

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:3.0.1.13) - 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  
Followers 0