Page 1 of 1
Form Datagrid Problems
Posted: Sun Jan 12, 2014 7:16 pm
by lohill
I have a datagrid that is in the table format on card 1. I would like to put the data from that grid into a datagrod on card 2 that is in the 'Form' format. I have constructed the grid on card 2 as a form and have the eight fields accounted for in the row template and in the scripts for row behavior. I have a button with the following script
Code: Select all
on mouseUp
put the dgData of group "DataGrid 1" of card 1 into tData
set the dgData of group "DataGrid 1" of card 2 to tData
end mouseUp
Before that script is run the data grid on card 2 shows nothing. After running that code, that grid in card 2 has a scroll bar but no data is visible.
I have created a second button with the following script:
Code: Select all
on mouseUp
put the dgData of group "DataGrid 1" into tData
put tData[1] into tArray
answer tArray["Universe"]
end mouseUp
When that script is run I get "SI Pro" displayed which is the data that should be visible but is not. Also I have put in the message box 'put the dgNumberOfRecords of group "DataGrid 1" and come up with 248. Clearly there is data in the grid but it is not visible. "Refresh Datagrid" doesn't seem to change things either.
Any suggestions to make the data visible would be appreciated.
Larry
Re: Form Datagrid Problems
Posted: Sun Jan 12, 2014 11:10 pm
by Zryip TheSlug
Hi Larry,
What is your row behavior script for the datagrid form?
You can open this script by clicking on the "Row behavior" button located in the first tab of the inspector.
In this behavior you need to change the FillInData handler by binding each fields in the row template with each array keys. Array keys are the column names of the datagrid table.
Assuming:
- we have at least, a column named "Universe" in the datagrid table, and "Col 2" and "Col 3" as others columns
- we have a row template for the datagrid form, composed by 3 fields: "Universe", "MyCol2", "MyCol3"
To have the datagrid form populated by the data of the datagrid table, when we are using the code:
Code: Select all
set the dgData of grp "Datagrid 1" of cd 2 to the dgData of grp "datagrid 1' of cd 1
We need to change the FillInData like this:
Code: Select all
on FillInData pDataArray
set the text of field "Universe" of me to pDataArray["Universe"]
set the text of field "MyCol2" of me to pDataArray["Col 2"]
set the text of field "MyCol3" of me to pDataArray["Col 3"]
end FillInData
Re: Form Datagrid Problems
Posted: Mon Jan 13, 2014 12:08 am
by lohill
These are the sections of my Row Behavior code that have changes:
Code: Select all
on FillInData pDataArray
-- This message is sent when the Data Grid needs to populate
-- this template with the data from a record. pDataArray is an
-- an array containing the records data.
-- You do not need to resize any of your template's controls in
-- this message. All resizing should be handled in resizeControl.
-- Example:
set the text of field "Universe" of me to pDataArray["Universe"]
set the text of field "nKey" of me to pDataArray["nKey"]
set the text of field "Radiscript Name" of me to pDataArray["Radiscript Name"]
set the text of field "GTR1 Name" of me to pDataArray["GTR1 Name"]
set the text of field "Label" of me to pDataArray["Label"]
set the text of field "Reference" of me to pDataArray["Reference"]
set the text of field "Deblank" of me to pDataArray["Deblank"]
set the text of field "Prior" of me to pDataArray["Prior"]
end FillInData
on LayoutControl pControlRect
local theFieldRect
-- This message is sent when you should layout your template's controls.
-- This is where you resize the 'Background' graphic, resize fields and
-- position objects.
-- For fixed height data grid forms you can use items 1 through 4 of pControlRect as
-- boundaries for laying out your controls.
-- For variable height data grid forms you can use items 1 through 3 of pControlRect as
-- boundaries, expanding the height of your control as needed.
-- Example:
put the rect of field "Universe" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "nKey" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "Radiscript Name" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "GTR1 Name" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "Label" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "Reference" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "Deblank" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
put the rect of field "Prior" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "Label" of me to theFieldRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
on ResetData
-- Sent when data is being emptied because the control is no longer being used to display data
set the text of field "nKey" of me to empty
set the text of field "Universe" of me to empty
set the text of field "Radiscript Name" of me to empty
set the text of field "GTR1 Name" of me to empty
set the text of field "Label" of me to empty
set the text of field "Reference" of me to empty
set the text of field "Deblank" of me to empty
set the text of field "Prior" of me to empty
end ResetData
I'm pretty sure the date is all there but for some reason not visible.
Re: Form Datagrid Problems
Posted: Mon Jan 13, 2014 8:22 pm
by lohill
I threw away the old datagrid and its associated row template and created another one. This time I can see some of the data and I suspect it would be all except the fields are not where I placed then on the form but hundreds of pixels to the right and below where I placed them. Any thoughts? What are the rolls of the label and background that come as part of a new datagrid?
Larry
Re: Form Datagrid Problems
Posted: Mon Jan 13, 2014 10:06 pm
by Zryip TheSlug
Larry,
Your LayoutControl handler seems correct. But did your try to comment it for a quick try?
Keep only the line for resizing the background graphic. The datagrid should keep the fields as they have been placed in the row template.
Code: Select all
on LayoutControl pControlRect
set the rect of graphic "Background" of me to pControlRect
end LayoutControl
Re: Form Datagrid Problems
Posted: Mon Jan 13, 2014 11:25 pm
by lohill
Thanks TheSlug,
That bit about commenting out the lines in the Layout Control really helped. Can I just leave them that way?
My 'too far right and too far down' problem was a problem with my group containing more space that I thought. The cleanup by repositioning everything has made everything just about right. The only problem I have left is the chasing down of why one field did not get filed with data.
Larry
Re: Form Datagrid Problems
Posted: Tue Jan 14, 2014 9:57 pm
by lohill
I have a form datagrid that looks like it should work now but my reason for making it a form instead of a table was because I wanted to have some scrolling fields to accommodate multiple lines each. When I put data into the grid that contains multiple lines only the first line makes it into the grid at the appropriate place. The other lines end up falling into other 'new' rows of the grid. Am I trying to do something that is not possible?
Thanks in advance for any suggestions,
Larry
Re: Form Datagrid Problems
Posted: Tue Jan 14, 2014 11:28 pm
by lohill
As a test I have a table grid ("DataGrid 1") and a form grid ("DataGrid 2) that are populated with the following code:
Code: Select all
on mouseUp
set the dgText of group "DataGrid 1" to empty
set the dgData of group "DataGrid 2" to empty
put "SELECT nKey,universe,radiname,gtr1name, label,gtr1description,deblank,prior FROM radifields" into tSQL
put ExecuteSQL(tSQL) into tList
set the dgText of group "DataGrid 1" to tList
set the dgData of group "DataGrid 2" to the dgData of group "DataGrid 1"
end mouseUp
When either grid is scrolled there is what I call spill over for the record with database key 251 (the only record that has fields with more than 1 line of content). By spill over I mean that the grid item displaying 251 shows only one line of data in the fields of multiple lines while the 'spilled' data shows the missing lines of data in other rows of the grid
A test button with the following code (where either data grid may be substituted) looks like this:
Code: Select all
on mouseUp
put the dgHilitedIndex of group "DataGrid 1" into tIndex
If tIndex>0 then
put the dgDataOfIndex[tIndex] of group "DataGrid 1" into tData
put tData["nKey"] into tKey
put "SELECT * FROM radifields WHERE nKey=" & tKey into tSQL
put ExecuteSQL(tSQL) into tResult
set the itemdelimiter to tab
repeat with i=1 to number of items of tResult
put item i of tResult into tItem
answer i & tab & tItem
end repeat
else
answer information "A row must be selected."
end if
end mouseUp
Selecting the grid line (251) that is supposed to display multiple line for a couple of fields gives these results on debugging:
The array tData shows exactly one line of data for each element while the repeat loop showing supposedly the same database information shows that two of the fields have multiple lines in them.
Can you spot anything here that might help me get this working?
Larry
Re: Form Datagrid Problems
Posted: Fri Jan 17, 2014 6:32 pm
by lohill
Well, after four days of banging my head against the wall I finally have the answer. Interestingly, I came to the realization while trying to produce a simple demonstration of how the 'spill over' was produced. I couldn't do it. I discovered that both the datagrid table and datagrid form are perfectly capable of having fields containing multiple lines the only difference is that in the table only the first line of the field will be visible. The trick is in how you put the data into the table and form.
My data source is a SQLite database and I was selecting all fields from all records into tab delimited list. As long as the none of the fields had multiple lines, a simple 'set the dgText of group "DataGrid 1" to tList'' was just fine. As soon as one field of one record had more than one line I would get the 'spill over'. To make a long story short, what was required was to go through tList one record at a time and put the items of each record into array format. For each record I would 'put tArray into tData' where i ranged from 1 to the number of records. Finally 'set the dgData of group "DataGrid 1" to tData' gave me what I wanted. Even though a bit cumbersome, LiveCode could handle it very quickly for a few hundred records.
Larry