Using the Dialogs example, if I want to be able to save the list into a file and import it, how to do that?
And if I want to export it to a normal hollywood table?
How to export and import a listview?
-
- Posts: 475
- Joined: Fri May 15, 2015 5:15 pm
- Location: Waterville, Minnesota USA
Re: How to export and import a listview?
The procedure for dumping the entries in a listview to a table involves looping through Listview.Entries times. You retrieve all the columns as return codes from Listview.GetEntries and assign them to fields in the inner tables (one table per row). And add each inner table to an outer table as an array. Using the new array optimizations in Hollywood 9 will speed this up.
Once the data is in a table, using WriteTable to serialize the data to disk is easy. I would suggest using WriteString before WriteTable to indicate the file format.
Reversing the process is as simple as using ReadString and comparing to the "cookie" value used to identify your file format, using ReadTable, then using Listview.Insert to add your entries back into the listview, line by line.
Once the data is in a table, using WriteTable to serialize the data to disk is easy. I would suggest using WriteString before WriteTable to indicate the file format.
Reversing the process is as simple as using ReadString and comparing to the "cookie" value used to identify your file format, using ReadTable, then using Listview.Insert to add your entries back into the listview, line by line.
I'm on registered MorphOS using FlowStudio.
Re: How to export and import a listview?
phew... I got the feeling you gave me a riddle to solve there:)
But your clues helped me to get started, so now I do have a working save / load routine.
I was not sure where you ment I should use writeline, but using the adapter ="default" resulted in a readable textfile anyway.
Thank you for your help, here is the code I found working
But your clues helped me to get started, so now I do have a working save / load routine.
I was not sure where you ment I should use writeline, but using the adapter ="default" resulted in a readable textfile anyway.
Thank you for your help, here is the code I found working
Code: Select all
Function p_save()
deltakerliste = CreateList()
For i = 0 To moai.Get("lv", "Entries")-1
Local etternavn$, fornavn$, adresse$, postnr$, sted$, fdato$, klasse$, deltatt$, kommentar$ = moai.DoMethod("lv", "getentry", i)
InsertItem(deltakerliste, {etternavn$, fornavn$, adresse$, postnr$, sted$, fdato$, klasse$, deltatt$, kommentar$})
Next
OpenFile(1, "deltakere.dat", #MODE_WRITE)
WriteTable(1, deltakerliste, {Adapter = "Default"})
CloseFile(1)
EndFunction
Function p_load()
If Exists("deltakere.dat")
moai.DoMethod("lv", "clear")
OpenFile(1, "deltakere.dat", #MODE_READ)
deltakerliste = ReadTable(1, {Adapter = "default"})
CloseFile(1)
For i = 0 To ListItems(deltakerliste)-1
etternavn$ = deltakerliste[i][0]
fornavn$ = deltakerliste[i][1]
adresse$ = deltakerliste[i][2]
postnr$ = deltakerliste[i][3]
sted$ = deltakerliste[i][4]
fdato$ = deltakerliste[i][5]
klasse$ = deltakerliste[i][6]
deltatt$ = deltakerliste[i][7]
kommentar$ = deltakerliste[i][8]
moai.DoMethod("lv", "insert", "bottom", etternavn$, fornavn$, adresse$, postnr$, sted$, fdato$, klasse$, deltatt$, kommentar$)
Next
EndIf
EndFunction
Re: How to export and import a listview?
I just noticed that when sorting a listview it will be sortet i the visible list on screen. But when exporting it to a file, it will be in the original order as before it was sorted.
Is there a way to sort the list permanently?
Is there a way to sort the list permanently?