Jump to content

Saving ListViews...


Recommended Posts

when making a list view with a bunch of information, how would one save it and then go back to it later..? when i do it, it comes back as "0".

can somebody help?

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Link to comment
Share on other sites

when making a list view with a bunch of information, how would one save it and then go back to it later..? when i do it, it comes back as "0".

can somebody help?

Look in your Includes for GUIListView.au3

Use _GUICtrlListViewGetItemText and _GUICtrlListViewSetItemText. Remember that items are indexed starting at 0

Edit: You may have to save the text to a file then read it back later.

Edited by GEOSoft

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!"

Link to comment
Share on other sites

i cant seem to get it still. heres the script.

#include <GUIConstants.au3>
#include <GuiListView.au3>

$d = GUICreate("Vehicle Statistics", 400,400,-1,-1)

$filemenu = GUICtrlCreateMenu("&File");
$addS = GUICtrlCreateMenuItem("&Add Data/Car...",$filemenu)
$deleteS = GUICtrlCreateMenuItem("&Delete Selected Item",$filemenu)
$save = GUICtrlCreateMenuItem("&Save Car Information",$filemenu)
    GUICtrlCreateMenuItem("",$filemenu)
$exit = GUICtrlCreateMenuItem("&Exit",$filemenu)
$listview = GUICtrlCreateListView("Statistics  /Make|Description  /Model",0,0,400,310,$LVS_EDITLABELS,$LVS_EX_HEADERDRAGDROP)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
$item1=GUICtrlCreateListViewItem("Create a car first|Then delete this line",$listview)
$Input_3 = GUICtrlCreateInput("", 40,315,320,22)
GUICtrlSetState(-1,$GUI_DROPACCEPTED) 
$delete_button = GUICtrlCreateButton("Delete Selected Item", 40, 345,135,22)
$add_button = GUICtrlCreateButton("Add Stat...", 185, 345,75,22)

GUISetState(@SW_SHOW)

$addsGUI = GuiCreate("Add Stats...", 380, 130,-1, -1,"","",$d)

$Input_1 = GuiCtrlCreateInput("", 20, 30, 160, 20)
$Input_2 = GuiCtrlCreateInput("", 200, 30, 160, 20)
$Label_3 = GuiCtrlCreateLabel("Statistic/Make", 20, 10, 160, 20)
$Label_4 = GuiCtrlCreateLabel("Description/Model", 200, 10, 160, 20)
$Button_5 = GuiCtrlCreateButton("Ok", 20, 70, 50, 20)
GUICtrlSetState(-1,$gui_focus)
$Button_6 = GuiCtrlCreateButton("Close", 80, 70, 50, 20)

GuiSetState(@SW_HIDE)


while 1
    $i = GUIGetMsg()
    if $i = $Button_5 Then
        GUICtrlCreateListViewItem(GUICtrlRead($Input_1)&"|"&GUICtrlRead($Input_2),$listview)
        GUICtrlSetData($Input_1,"")
        GUICtrlSetData($Input_2,"")
        GUICtrlSetState($Input_1,$gui_focus)

;~      GUISetState(@SW_hide, $addsGUI)
    EndIf
    
    If $i = $save Then
        $file = FileSaveDialog("Save File", "", "Text (*.txt)", 18, "");
        If Not @error Then
            FileDelete($file);
            FileWrite($file, GUICtrlRead(GUICtrlRead($listview)));          
        EndIf
    EndIf
    if $i = $Button_6 Then
        GUISetState(@SW_hide, $addsGUI)
    EndIf
    if $i = $deleteS Then
        _GUICtrlListViewDeleteItemsSelected ($listview)
    EndIf
    if $i = $delete_button Then
        _GUICtrlListViewDeleteItemsSelected ($listview)
    EndIf  

    if $i = $gui_event_close then
        Exit
    EndIf
    if $i = $exit then
        Exit
    EndIf
    if $i = $addS Then
        GUISetState(@SW_SHOW, $addsGUI)
    EndIf
    if $i = $add_button Then
        GUISetState(@SW_SHOW, $addsGUI)
    EndIf
    
WEnd

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Link to comment
Share on other sites

If Not @error Then
            FileDelete($file);
            FileWrite($file, GUICtrlRead(GUICtrlRead($listview)));    
        EndIf

Change to

If Not @Error Then
   FileDelete($file)
   $Count = _GUICtrlListViewGetItemCount ( $listview )
   For $J = 0 To $Count -1
      FileWriteLine($File, _GUICtrlListViewGetItemText ( $h_listview, $J))
   Next
EndIf

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!"

Link to comment
Share on other sites

thats exactly what i wanted, thank you so much, you dont by chance know how to open it back up n the same list again, do you...

if not thats ok. thanks again

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Link to comment
Share on other sites

thats exactly what i wanted, thank you so much, you dont by chance know how to open it back up n the same list again, do you...

if not thats ok. thanks again

This should do it as long as the ListViewItems do not already exist

$r_File = ''
_FileReadToArray($File, $r_File)
For $I = 1 To $r_File[0]
   _GUICtrlListViewInsertItem($listview,$I-1, $r_File[$I])
Next

EDIT:

I should have mentioned that _FileReadToArray() is in File.au3

If That's the only function that you are using from that UDF then just copy the function into your script because as I recall it doesn't require anything else. If you have a problem then #include <file.au3>

Edited by GEOSoft

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!"

Link to comment
Share on other sites

Here's another small change to your script

while 1
    $i = GUIGetMsg()
    $s_Count = _GUICtrlListViewGetSelectedCount ( $listview )
    If $s_Count < 1 Then
       If GUICtrlGetState($deleteS) <> 128 Then GUICtrlSetState($deleteS, 128)
    Else
       If GUICtrlGetState($deleteS) > 64 Then GUICtrlSetState($deleteS, 64)
    EndIf

That should make your "Delete selected item" MenuItem disabled if there is nothing selected.

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!"

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...