Page 1 of 1

Data Grid Forms: Can't populate them

Posted: Sun Jan 01, 2017 6:01 pm
by ittarter
Hello!

So I've successfully created my first array using the following code:

Code: Select all

repeat until revQueryIsAtEnd(theData)
add 1 to tCounter
put revDatabaseColumnNamed(theData, "f_UserName") into tUserList[tCounter]["UserName"]
put revDatabaseColumnNamed(theData, "f_Email") into tUserList[tCounter]["Email"]
put revDatabaseColumnNamed(theData, "f_Avatar") into tUserList[tCounter]["Avatar"]
revMoveToNextRecord theData
end repeat
set the dgData of group "User List" to tUserList
I've checked that tUserList is populating successfully. No problems there.

From there I've gone into my data grid, group "User List", to set the row template and adjust the script accordingly.
I have four objects in group id 1012: fld "email", fld "username", img "avatar" and graphic "background"
So in the handler fillInData of btn "behavior script" I have:

Code: Select all

set the text of field "Email Address" of me to tUserList["Email"]
set the text of field "Username" of me to tUserList["Username"]
set the filename of image "Avatar" of me to tUserList["Avatar"]
However when I refresh the data nothing happens...

I think I did everything that was in the guide. What am I missing here? What else do I have to do?

Thanks for your time!

Ivan

Re: Data Grid Forms: Can't populate them

Posted: Mon Jan 02, 2017 12:27 am
by jameshale
Try...

Code: Select all

set the text of field "Email Address" of me to pDataArray["Email"]
set the text of field "Username" of me to pDataArray["Username"]
set the filename of image "Avatar" of me to pDataArray["Avatar"]

Re: Data Grid Forms: Can't populate them

Posted: Mon Jan 02, 2017 11:12 am
by Klaus
Yes, looks like you are using the SAME variable (pDataArray) for both setting the DGDATA
of your datagrid and also for the "fillindata" handler.

Do like James proposed and use another variable for the FILLINDATA handler:

Code: Select all

on fillindata pDataAray
    set the text of field "Email Address" of me to pDataArray["Email"]
   ### etc.
end fillindata

Re: Data Grid Forms: Can't populate them

Posted: Mon Jan 02, 2017 3:46 pm
by ittarter
Thanks, James and Klaus.
Klaus wrote:Yes, looks like you are using the SAME variable (pDataArray) for both setting the DGDATA
of your datagrid and also for the "fillindata" handler.
Oh, we can't do this? So after I've set the dgData property, I then access it through the pDataArray property? (It's strange that it changes names, since it contains the same information...). Could I get the information by using dgData["Avatar"] or something like that?

I thought that was just a variable that was given an arbitrary name for convenience's sake :P

Re: Data Grid Forms: Can't populate them

Posted: Mon Jan 02, 2017 4:04 pm
by Klaus
Hi Ivan,

you set the DGDATA of a datagrid to a MULTI-dimensional array!
tUserList[1]["UserName"]
tUserList[1]["Email"]
tUserList[2]["UserName"]
tUserList[2]["Email"]
etc...

But the "fillindata" handler needs a SINGLE dimensional array, so these are in fact dfifferent variables with different content!

Code: Select all

on fillindata ANYOTHERVARIABLENAME
   set the text of field "Email Address" of me to ANYOTHERVARIABLENAME["Email"]
   ...
See the difference?

You can name the variables as you want, but see above, they are different!


Best

Klaus

Re: Data Grid Forms: Can't populate them

Posted: Mon Jan 02, 2017 4:10 pm
by jameshale
Oh, we can't do this? So after I've set the dgData property, I then access it through the pDataArray property? (It's strange that it changes names, since it contains the same information...). Could I get the information by using dgData["Avatar"] or something like that?
They do not contain the same info.
In effect dgData is a numerically indexed array of pDataArrays
Each index of dgData contains one record (array) of your values.

Re: Data Grid Forms: Can't populate them

Posted: Thu Jan 05, 2017 3:51 pm
by MaxV
Dear ittarter,
the code seems correct to me, but... you personalized it, so
is the datagrid a table or a form?

If it is a table, then read here: http://livecodeitalia.blogspot.it/2016/ ... agrid.html

Do you edited the row template correctly, did you edit the column behavior correctly for each column?
Image

Re: Data Grid Forms: Can't populate them

Posted: Thu Jan 12, 2017 2:55 pm
by ittarter
Sorry for not writing back sooner.

Unfortunately, it still doesn't work.

I can see a tab delimited table of information in the contents tab of my group "User list" (I imagine this represents the dgData of the datagrid)
But when I click refresh, it doesn't display. (Minor question: Is the best way to refresh the datagrid to just type "refresh group "User List"?)

To confirm, MaxV, I'm using a form, not a table. There are no column templates or column behavior.

So Klaus and James said to use a different variable name for my single dimensional array. Fine.

on fillindata pDataArray
set the text of field "Email Address" of me to pDataArray["Email"]
...
end fillindata

This still does nothing. I can think of two possible reasons. 1. pDataArray is empty, even though dgData isn't. 2. dgData doesn't know which column is represented by "Email".

So 1. how do I set pDataArray as the current array of dgData? or 2. where are the "column headers" stored, if not in dgData?

EDIT. As a side-note, I can stop my code after it's created tUserList, and I can see the names of the arrays "Email" "Avatar" etc., even though I can't find them anywhere in the properties of group "User List". So that's probably OK, even if I don't know how to actually confirm that the headers were in fact transferred over to the datagrid.

Re: Data Grid Forms: Can't populate them

Posted: Thu Jan 12, 2017 3:26 pm
by jameshale
Which version of LC are you using. There was a problem with the resfresh button in the early LC8's.
Also, are you seeing anything in your data grid. If you have an error in your layout you may see nothing at all.
I do not know how you have laid out the fields in your form and whether you adjusted the layout code too.
When something like this happens I simplify and start with trying to display one field, and then the next etc. to do this I would comment out the extra fillndata assignment lines.

Re: Data Grid Forms: Can't populate them

Posted: Thu Jan 12, 2017 3:55 pm
by ittarter
I'm using 8.1.2.

I see the different rows and they're the correct height.

Layout code? I thought that was optional or automatic. Doesn't the datagrid know to just put objects relative to where they are in the template row? I'm not using variable height forms yet or anything. I don't have any active code in the handler layoutControl.

Re: Data Grid Forms: Can't populate them

Posted: Thu Jan 12, 2017 11:18 pm
by jameshale
I am a bit confused with you terminology though.
You stated you are using a "Form" data grid yet you keep speaking of rows.
Anyway, you will notice a layout handler in the form's behaviour. It is called 'LayoutControl'.
At the very least you would have done something to this,as it refers to the initial field in the layout template. I am assuming you have deleted this filed to replace it with your own. Given this it would flag an error unless you commented out the line referring to it.

Re: Data Grid Forms: Can't populate them

Posted: Fri Jan 13, 2017 8:44 am
by ittarter
Hi James
I am using a data grid form. Each form employs one row template. To my knowledge, tables employ multiple column templates instead.
I am aware of the handler LayoutControl, but there is no active code within that handler.
jameshale wrote:I am assuming you have deleted this filed to replace it with your own. Given this it would flag an error unless you commented out the line referring to it.
I'm not sure what you mean here. I did comment out the original code because I wasn't at the stage of actively reshaping my form and it didn't refer to the object that actually existed in the form's row template, since I had set up my own objects. At this point I have not written any new or active code for LayoutControl.

Re: Data Grid Forms: Can't populate them

Posted: Fri Jan 13, 2017 9:13 am
by jameshale
Cool.
Two things.
In your initial post you state you made a field "email" yet you are setting the contents of field "email address" in your script.
If this is not a typo the you need to set the contents of field "email".
Secondly, try commenting out the line setting the avatar to see if there is an issue here.

Re: Data Grid Forms: Can't populate them

Posted: Tue Jan 17, 2017 3:42 pm
by ittarter
Hi James,

I figured it out by starting over from scratch.

Apparently LayoutControl is NOT optional :)
Also I hadn't grouped my new field and image into the necessary group for the datagrid to track down.

I'm still having bugs but I will post about it in a separate post.

Thanks for all your help

Re: Data Grid Forms: Can't populate them

Posted: Tue Jan 17, 2017 4:07 pm
by jameshale
Once you get your head around it you will be fine.
One of the first things I do when something doesn't work is to simplify it, or failing that, do it again.
And yes, the grouping in the form layout is critical and so easy to mess up.
Glad you have solved this one.