Page 1 of 1
How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 4:44 pm
by Knightlite
Hi,
I have a question on how you load items on to the scrolling list view. I can't find anything that shows the code for doing this. I want to load the records of a single field SQLite table on to the scrolling list field, which I assume is the equivalent of a ListBox in VB and RealBasic.
In RealBasic I have this code and it works.
Code: Select all
While Not rs.eof
List1.AddRow(rs.Field("Chapter").StringValue)
rs.MoveNext
wend
But what code would you use for loading the field in LiveCode?
Also, another question... How do I load the text for a text field of one card onto the text field of another card? I know these are basic questions, but I have been searching the documentation and this forum, and I can't find anything.
I am from a Visual Basic and RealBasic background so, I trying to yet used to the LiveCode syntax.
In RealBasic it would be:
Code: Select all
Card2.txtCard2.Text = Card1.txtCard1.Text
What is the equivalent in LiveCode?
Any help would be greatly appreciated.
Jim
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 5:27 pm
by mwieder
Here's where LiveCode's string- and chunk-handling capabilities really shine.
Assuming you've already got your SQL result handy in tData and your scrolling list is named "List1"
Code: Select all
put tData & cr after field "List1"
will put a new line containing your string at the end of the List1 list. You can put it at the top of the list with
Code: Select all
put tData & cr before field "List1"
or anywhere in between
Code: Select all
put tData & cr before line 3 of field "List1"
...and to put it into card 2's field one way would be just to copy it
Code: Select all
put field "List1" into field "List1" of card 2
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 6:43 pm
by Knightlite
Hi mwieder,
Thank you so much for taking the time to help me. I guess I am a little confused as to how to popular the list with all the records in an SQLite table.
This is the code I have to create the recordset:
Code: Select all
.........
## Query all details
## Save the recordset id
put "SELECT * from Chapters" into tSQLQuery
put revQueryDatabase(sDatabaseID,tSQLQuery) into sRecordSetID
## Display the first record
revMoveToFirstRecord sRecordSetID
displayRecord
end preOpenCard
I then need to populate the List field with the records. I have this code:
Code: Select all
put revDatabaseColumnNamed(sRecordSetID,"Chapter") into field "List1"
revMoveToNextRecord sRecordSetID
I need some sort of loop around the two lines of code above, so it keeps adding to the list and loops through each record until it reaches the end.
I don't really understand how your code will accomplish this. Could you possibly explain that further?
Your help is very much appreciated.
Jim
PS
Thanks for this code. That worked great.
Code: Select all
put field "List1" into field "List1" of card 2
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 7:10 pm
by mwieder
Changing
Code: Select all
put revDatabaseColumnNamed(sRecordSetID,"Chapter") into field "List1"
to
Code: Select all
put revDatabaseColumnNamed(sRecordSetID,"Chapter") & cr after field "List1"
sounds like it should do what you want. Putting data "into" the field will just overwrite what is currently there.
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 7:49 pm
by Knightlite
Hi mwieder,
This is the code I have:
Code: Select all
## Query all details
## Save the recordset id
put "SELECT * from Chapters" into tSQLQuery
put revQueryDatabase(sDatabaseID,tSQLQuery) into rsRecordSetID
//Loads record into List1
put revDatabaseColumnNamed(rsRecordSetID,"Chapter") & cr after field "List1"
end preOpenCard
What is does is that it puts the first record into the Listbox but thats it. It does not loop and add all the records in the table as a list in the box. I don't know how to make the loop. I would think it would be something like the following:
Code: Select all
Do This code until EOF
put revDatabaseColumnNamed(rsRecordSetID,"Chapter") & cr after field "List1"
revMoveToNextRecord sRecordSetID
End of Do Code.
I just know what the syntax would be for that loop code.
Jim
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 7:55 pm
by mwieder
Ah - OK... got it. I misunderstood the question before. Something like this?
Code: Select all
--Do This code until EOF
repeat while sRecordSetID is a number
put revDatabaseColumnNamed(rsRecordSetID,"Chapter") & cr after field "List1"
revMoveToNextRecord sRecordSetID
if the result is false then
exit repeat
end if
end repeat
--End of Do Code.
Re: How Do I Use The Scrolling List Field?
Posted: Thu Mar 29, 2012 8:08 pm
by Knightlite
Thank you so much!!! That worked perfectly!!! Thats exactly what I was looking for. Thank you very much for your help.
I really appreciate you taking the time
Jim