Sign in to follow this  
Followers 0
razor999

(HELP) ListViewItem, Save and Load

3 posts in this topic

#1 ·  Posted (edited)

please help me,

my script error and not working

I want :

- sort list number in # after add

- list input name item on Name Item after add

- save ini file anytime

- and load ini file anytime

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=
$Frm_Main = GUICreate("ItemList", 160, 273, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Frm_MainClose")
$Lst_Values = GUICtrlCreateListView("#|Name Item", 10, 8, 140, 160, BitOR($GUI_SS_DEFAULT_LISTVIEW,$WS_BORDER))
$Lst_Handle = GUICtrlGetHandle($Lst_Values)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 25)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)

$NameItem = GUICtrlCreateInput("Name Item",10, 170, 100, 20)

$Btn_Add = GUICtrlCreateButton("Add", 36, 218, 46, 25)
GUICtrlSetOnEvent(-1, "AddClick")
$Btn_Save = GUICtrlCreateButton("Save", 36, 242, 46, 25)
GUICtrlSetOnEvent(-1, "save")
$Btn_Load = GUICtrlCreateButton("Load", 84, 242, 46, 25)
GUICtrlSetOnEvent(-1, "load")
$Exit = GUICtrlCreateButton("Exit", 84, 218, 46, 25)
GUICtrlSetOnEvent(-1, "Frm_MainClose")

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
Sleep(100)
WEnd

Func AddClick()
    For $i = 1 To +1 
        GUICtrlCreateListViewItem($i & "|" &$NameItem, $Lst_Values)
    Next
EndFunc

Func save()
    $Nameini = FileSaveDialog( "Choose a name.", @ScriptDir, "(*.*)", 1 + 2)
        If @error Then
                MsgBox(4096,"","Save cancelled.")
        Else
            For $i = 1 To + 1
                    IniWrite($Nameini, "Coordinates", "coord", GUICtrlCreateListViewItem($i & "|" &$NameItem, $Lst_Values))
            Next
                MsgBox(64, "Info", "Item Saved")
        EndIf
EndFunc


Func load()
    $Nameini = FileOpenDialog("Open a File", @ScriptDir, "(*.*)", 1 + 2)
        If @error Then 
                MsgBox(4096, "", "No File(s) chosen")
        Else
            For $i = 1 To + 1
                GuiCtrlSetData($Lst_Values, $i)
            Next
        EndIf
EndFunc


Func Frm_MainClose()
    Exit
EndFunc

please help me, because this task from college

Edited by razor999

Share this post


Link to post
Share on other sites



Here is one way of doing it.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <guilistview.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)
Global $Count = 0, $Nameini
#Region ### START Koda GUI section ### Form=
$Frm_Main = GUICreate("ItemList", 160, 273, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Frm_MainClose")
$Lst_Values = GUICtrlCreateListView("#|Name Item", 10, 8, 140, 160, BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_BORDER))
$Lst_Handle = GUICtrlGetHandle($Lst_Values)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 25)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 80)
$NameItem = GUICtrlCreateInput("Name Item", 10, 170, 100, 20)
$Btn_Add = GUICtrlCreateButton("Add", 36, 218, 46, 25)
GUICtrlSetOnEvent(-1, "AddClick")
$Btn_Save = GUICtrlCreateButton("Save", 36, 242, 46, 25)
GUICtrlSetOnEvent(-1, "save")
$Btn_Load = GUICtrlCreateButton("Load", 84, 242, 46, 25)
GUICtrlSetOnEvent(-1, "load")
$Exit = GUICtrlCreateButton("Exit", 84, 218, 46, 25)
GUICtrlSetOnEvent(-1, "Frm_MainClose")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    Sleep(100)
WEnd
Func AddClick()
    GUICtrlCreateListViewItem($Count & "|" & GUICtrlRead($NameItem), $Lst_Values)
    $Count += 1
EndFunc   ;==>AddClick
Func save()
    $Nameini = FileSaveDialog("Choose a name.", @ScriptDir, "(*.*)", 1 + 2)
    If @error Then
        MsgBox(4096, "", "Save cancelled.")
    Else
        FileDelete($Nameini)
        For $i = 0 To _GUICtrlListView_GetItemCount($Lst_Handle) - 1
            IniWrite($Nameini, "Coordinates", "coord" & $i, _GUICtrlListView_GetItemTextString($Lst_Handle, $i))
        Next
        MsgBox(64, "Info", "Item Saved")
    EndIf
EndFunc   ;==>save
Func load()
    $Nameini = FileOpenDialog("Open a File", @ScriptDir, "(*.*)", 1 + 2)
    If @error Then
        MsgBox(4096, "", "No File(s) chosen")
    Else
        Local $Array = IniReadSection($Nameini, "Coordinates")
        _GUICtrlListView_DeleteAllItems($Lst_Handle)
        For $i = 0 To $Array[0][0] - 1
            Local $Item = IniRead($Nameini, "Coordinates", "coord" & $i, "")
            GUICtrlCreateListViewItem($Item, $Lst_Values)
        Next
    EndIf
EndFunc   ;==>load
Func Frm_MainClose()
    Exit
EndFunc   ;==>Frm_MainClose

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Genius, It worked!!!

thanks for the fast reply!

thanks for the prompt and easy solution.

again, Thank you!!!

OK, problem solved.

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