Page 1 of 1
Datagrid (FORM)
Posted: Fri Jul 12, 2024 6:48 pm
by lemodizon
Hi everyone,
Good day.
I'm practicing the datagrid (FORM) I'm trying to display all the data from my database using datagrid form but it display only the 1st record.
i tried using repeat i think there is wrong in my code. hope you can help me thanks in advance
here is my code
Code: Select all
command uiPopulatePeople
global gConnectionID
local tSQLStatement, tlist
put "C:\Users\CodeLemz\Documents\Zigzag project\ZigzagWeb\Picture/" into theImageFolder
put "SELECT * FROM sbcust " into tSQLStatement
put revDataFromQuery(tab,return, gConnectionID, tSQLStatement) into tlist
set the itemdel to tab
repeat for each line tLine in tlist
if item 1 of tlist is a number then
put item 2 of tlist into theDataA[1]["FirstName"]
put item 3 of tlist into theDataA[1]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[1]["Image URL"]
end if
end repeat
lock screen
set the dgData of group "DataGrid 1" to theDataA
## Hilite first row
set the dgHilitedLines of group "DataGrid 1" to 1
unlock screen
end uiPopulatePeople
Re: Datagrid (FORM)
Posted: Fri Jul 12, 2024 6:59 pm
by stam
I think the problem is with your repeat loop.
Code: Select all
repeat for each line tLine in tlist
if item 1 of tlist is a number then
put item 2 of tlist into theDataA[1]["FirstName"]
put item 3 of tlist into theDataA[1]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[1]["Image URL"]
end if
end repeat
All the data is written into the same key:
theDataA[1]. So you're continuously overwriting the same key with the the loop data.
You should have an inrememtal variable fore the the root key.
This should work:
Code: Select all
local x // initially empty / zero
repeat for each line tLine in tlist
if item 1 of tlist is a number then
add 1 to x // will start from 1 and increment every loop
put item 2 of tlist into theDataA[x]["FirstName"]
put item 3 of tlist into theDataA[x]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[x]["Image URL"]
end if
end repeat
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 4:54 am
by lemodizon
stam wrote: ↑Fri Jul 12, 2024 6:59 pm
I think the problem is with your repeat loop.
Code: Select all
repeat for each line tLine in tlist
if item 1 of tlist is a number then
put item 2 of tlist into theDataA[1]["FirstName"]
put item 3 of tlist into theDataA[1]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[1]["Image URL"]
end if
end repeat
All the data is written into the same key:
theDataA[1]. So you're continuously overwriting the same key with the the loop data.
You should have an inrememtal variable fore the the root key.
This should work:
Code: Select all
local x // initially empty / zero
repeat for each line tLine in tlist
if item 1 of tlist is a number then
add 1 to x // will start from 1 and increment every loop
put item 2 of tlist into theDataA[x]["FirstName"]
put item 3 of tlist into theDataA[x]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[x]["Image URL"]
end if
end repeat
Hi Stam,
Thanks it works question how can i display the other records from my tlist coz it only display the 1st record the rest it did not displayed.
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 6:18 pm
by stam
How have you set up the fillInData handler in the row template's behavior script?
This looks like you've not used "of me" when assigning values to fields.
2 tips:
1. Look at custom properties of the datagrid - use the dropdown menu in the property inspector in the "custom" tab and select "dgCache". This will show you the array of the datagrid with the data by index and the sequence of records. Open the disclosure triangle and inspect the array to ensure the correct records are there.
2. If the correct records are in the data grid's array as seen in its dgCache, then the issue is how you are showing this data and you you should inspect the fillInData handler in the row's behavior script.
When putting values into fields in that handler, you *must* specify <field name> of me. The 'of me' tells LC you're referring to the field of that specific row. If you don't it will only populate with the field of the first row.
I think that's may be happening, but let us know...
Obviously, if the issue is that the dgCache contains wrong data (ie 3 duplicates) you need to review the code that populates the dgData again...
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 6:27 pm
by jacque
I think you need to use the built-in increments like this:
Code: Select all
repeat for each line tLine in tlist
if item 1 of tLine is a number then
add 1 to x // will start from 1 and increment every loop
put item 2 of tLine into theDataA[x]["FirstName"]
put item 3 of tLine into theDataA[x]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[x]["Image URL"]
end if
end repeat
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 7:16 pm
by stam
jacque wrote: ↑Sat Jul 13, 2024 6:27 pm
I think you need to use the built-in increments like this:
Code: Select all
repeat for each line tLine in tlist
if item 1 of tLine is a number then
add 1 to x // will start from 1 and increment every loop
put item 2 of tLine into theDataA[x]["FirstName"]
put item 3 of tLine into theDataA[x]["Title"]
put theImageFolder & "close_window_48px.png" into theDataA[x]["Image URL"]
end if
end repeat
Hi Jacque, Lemodizon did exactly after I posted this handler above. Now there is the correct number of rows, but all have the first value.
I think this issue is due to the fillInData handler:
Code: Select all
on FillInData pDataArray
set the text of field "<field name>" of me to pDataArray["<field name key>"]
end FillInData
I've had this issue before: where I forget to refer to the field name as field <field name>
of me - without the 'of me' all fields display the first value even though the array contains each value, because the 'of me' localises the field to the row in question...
My usual process in similar situations is to first verify the data grid's array contains the correct data by inspecting its dgCache in the custom properties section of the property inspector, and if that is the case the next step is to inspect the fillInData handler - I think the last issue lies there.
S.
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 8:07 pm
by Klaus
The problem is or was using
tList instead of
tLine in the loop:
Code: Select all
...
repeat for each line tLine in tlist
if item 1 of tlist is a number then
...
Tha is what Jacque had fixed in her script!
Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 8:20 pm
by stam
Klaus wrote: ↑Sat Jul 13, 2024 8:07 pm
The problem is or was using
tList instead of
tLine in the loop:
Code: Select all
...
repeat for each line tLine in tlist
if item 1 of tlist is a number then
...
Tha is what Jacque had fixed in her script!
Quite right, I stand corrected. And well spotted Jacque

I hadn't spotted the OP was referencing the container
tList instead of the line
tLine inside the loop.
The process to troubleshoot is the same and if I was actually debugging this, I would have spotted that the dgCache contained incorrect data. That would always be step 1 before looking at the fillInData handler... but always more difficult to do if troubleshooting in my mind

Re: Datagrid (FORM)
Posted: Sat Jul 13, 2024 9:33 pm
by jacque
stam wrote: ↑Sat Jul 13, 2024 8:20 pm
Quite right, I stand corrected. And well spotted Jacque

I hadn't spotted the OP was referencing the container
tList instead of the line
tLine inside the loop.
It was easy to miss, there's only 2 characters difference. The brain tends to fill in the rest. Human brains are capricious.
Re: Datagrid (FORM)
Posted: Sun Jul 28, 2024 5:01 am
by lemodizon
Hi everyone,
Thanks everyone for the response.