Scuilib listview - getting results ?

Discuss any general programming issues here
Post Reply
gerograph
Posts: 27
Joined: Thu Mar 04, 2010 9:38 pm

Scuilib listview - getting results ?

Post by gerograph » Sat Mar 27, 2010 11:44 pm

Maybe I am blind, but I couldn't figure out, how to get the Entries or selected rows/items of a listview ?

How do I delete and add rows in a Listview ?

It should become an easy playlisteditor...

thanx for help

User avatar
Allanon
Posts: 442
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Scuilib listview - getting results ?

Post by Allanon » Mon Mar 29, 2010 12:43 am

Hello gerograph and sorry for the delay of my answer :)

Well first of all I've release a WIP version of the 0.7 along with the available documentation at this time, you (as well as anyone interested) can download the zip file following this link.

When you define you listview you can attach the event "OnChaged" so everytime an item of the listview is clicked your function is called, here is a simple example:

Code: Select all

...
scui.NewObject( #IFOCLASS_LISTVIEW, "ListView1", nil, nil, nil,
                { FieldNames = { "Year", "System Name", "Description", "A", "B", "C", "D" },
                  Sizes      = { 10, 30, 40, 5, 5, 4, 6 },
                  Entries    = { { "1936", "Z1 Computer", "First freely programmable computer", "1", "2", "1", "2" },
                                 { "1942", "ABC Computer", "-", "1", "2", "1", "2" },
                                 { "1944", "Harvard Mark I Computer", "-", "1", "2", "1", "2" },
                                 { "1946", "ENIAC 1 Computer", "...", "1", "2", "1", "2" },
                                 { "1948", "Todoroky", "Manchester Baby Computer & The Williams Tube", "1", "2", "1", "2" },
                                 { "1951", "UNIVAC Computer", "First commercial computer", "1", "2", "1", "2" },
                                 { "1953", "IBM 701 EDPM Computer", "First IBM Computer", "1", "2", "1", "2" },
                                 { "1954", "FORTRAN Computer Programming Language", "First successful high level programming language", "1", "2", "1", "2" },
                                 { "1955", "ERMA and MICR", "The first bank industry computer", "1", "2", "1", "2" },
                                 { "1958", "The Integrated Circuit", "Commonly known as 'The Chip'", "1", "2", "1", "2" },
                                 { "1962", "Spacewar Computer Game", "The first coimputer game invented", "1", "2", "1", "2" },
                                 { "1964", "Computer Mouse & Windows", "-", "1", "2", "1", "2" },
                                 { "1969", "ARPAnet", "The original Internet", "1", "2", "1", "2" }
                                 },
                   Mode = #OPTMODE_FREE,
                   RowHeight = 12,
                   Selected = { 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 }
                  },
                 { OnChanged = fChanged } )
...
As you can see I've attached the function "fChanged" to the event OnChanged, so everytime an item is clicked this function is called. Before the gadget creation you have to define the fChanged function as following (just to test):

Code: Select all

Function fChanged(msg)
   DebugPrint("--- One ListView item has changed its state! ---")
   helpers.DumpTable(msg)
EndFunction
The function "helpers.DumpTable()" will dump all the table contents that will be passed when the event is detected, when an item is clicked you should receive the folliwing msg table members:
item --> The number of the item clicked (the row)
id --> The id of the gadget (the id of the ListView)
data --> this is a subtable with n items, one for each column of the clicked row
event --> DOWN->UP if the item has been deselected or UP->DOWN if the item has been selected
itemvalue --> can be 1 if the item is selected or 0 if teh item is not selected
If you want to query the ListView for further data you can use:

Code: Select all

gad = scui.Get(gadget_name)
Since you are querying a ListView you will obtain a table (named gad) with the following most important fields:
Position --> a table with the "x" and "y" fields for the coordinates of the ListView
Size --> a table with the "x" and "y" fields for the size of the ListView
Mode --> the select mode
FieldCount --> the number of columns
FieldNames --> the names of the columns
EntriesCount --> how many entries are in the listview
Entries --> the items listed in the listview
Selected --> a table with the values 0 for the not selected rows and 1 for the selected rows
Now, if you want to change the entries in your ListView is very simple, just use the command:

Code: Select all

scui.Set(gadget_name, tags, redraw)
In your specific case:

Code: Select all

scui.Set(ListView_Name, { Entries = your_entries_table }, 1)
You want to change the item 2 of your listview? Simple:

Code: Select all

LV_Gad = scui.Get(YourListView)
Lv_Gad.Entries[2] = { field1, field2, field2, ... }
scui.Set(YourListView, { Entries = LV_Gad.Entries }, 1)
Remember that the entries you get with the command scui.Get() is sorted in the same way as the items are displayed, as well as the "selected" table.

Actually this gadget is not optimized so speed is not its key feature ;)
Hope to have helped, if you need more informations just ask

Allanon
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

Post Reply