How do I enter items into listview dynamically

Discuss GUI programming with the RapaGUI plugin here

How do I enter items into listview dynamically

Postby Redlion » Wed Oct 05, 2016 3:25 pm


I am trying to write a simple SQL database viewer and have solved most problems but I an stuck on how to get items into the columns of the listview gadget.
The problem is that the number of columns will change with different Databases.
I can create the number of columns in the listview gadget dynamically, just can not get the dat in.

This is the function I have

Code: Select all
Global tablename$   ; Table Name
Global DB$               ; Database Name
Global RD = {}          ; Record Data
;Field[] = field names
;count = number of fields in DB Table
;fieldlist string of all columns in Table

Function p_GetDBRecord() ; ******************************************************************************
    db =$)
    For row In db:nrows("SELECT * FROM " .. tablename$ )
   For Info = 0 To Count-1
       RD[Info] = row[""..field[Info].. ""]
       fieldlist$ = fieldlist$ .."\""..rd[Info].."\", "
   len = StrLen(fieldlist$)
   fieldlist$ = MidStr(fieldlist$,0,len-2)
   fieldlist$ = ""

the problem is with the line moai.DoMethod("dbinfo","insert","bottom",fieldlist$)

If I hard code the fieldlist$,
ie. list all the columns I have in the database

moai.DoMethod("dbinfo","insert","bottom",RD[1],RD[2],rd[3], .....) for all the fields it works
but as the number of fields in different databases will have different numbers of fields that will not work.
I tried to create a string of the columns ie fieldlist$ = fieldlist$ .."\""..rd[Info].."\", "
but I get an error string expected in agument 5. - in Function DoMethod

Does anyone know how i can represent all the columns of the listview as a table or string that moai.DoMethod will not throw up an error with.

Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
User avatar
Posts: 62
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: How do I enter items into listview dynamically

Postby airsoftsoftwair » Fri Oct 07, 2016 10:27 pm

If you have a variable number of items, you could just use the Unpack() function to unpack items from a table, e.g.

Code: Select all
test$ = {"One", "Two", "Three"}

This will insert the three items into the three columns. Note that this code will only work if your listview has as many columns as the table you pass to Unpack() has items, i.e. if your listview has three columns, then the table you pass to Unpack() must have three items as well.
User avatar
Posts: 2025
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany

Return to RapaGUI

Who is online

Users browsing this forum: No registered users and 1 guest