Page 1 of 1

Datagrid

Posted: Thu Feb 16, 2012 7:49 pm
by JoeZimmerman
At this point I'd be pulling my hair out if i had any anymore. I'm trying to figure out why i can't get a data grid to work. I have the data in an excel file and i exported to tab delimited text file. i want to import this data at build time and just display it in a data grid FORM. Very similar layout as this example: example-creating-a-list-of-people . At this point i've deleted all the datagrid tests I've made so I can't show you what I have right now. What i'm after is a few answers as to my approach at this point.

1. The data will not be edited by the user. Only displayed. For now I was importing the text file in the properties (content) section. It asked if I had headers and I clicked yes. Problem is it still showed the headers in the content section is that correct? Also are those headers what I use to reference the code? I had something similar to : set the text of field "Artist" of me to pDataArray["Artist"] where Artist was the name of the label in the form builder and Artist was the header of the column in my table. Should that not have populated the data of that column into that or am i misunderstanding the data array? I don;t even know how to trouble shoot this to find where the issue lines. I just see a blank table. Now if I use a regular table and not a form the data shows.

2. Down the line i'd like to display select records based on the value of one of the columns. Is that possible with the data grid itself or would that require a function done prior to populating the data grid?

Re: Datagrid

Posted: Fri Feb 17, 2012 5:11 am
by dunbarx
Are you saying you cannot populate a datagrid at all?

Make one with a few columns and a few lines. Form a tab and return delimited piece of data that should fit that format. Are you unable to:

set the dgText of group "yourGroup" to yourData?

Start with that and move upward and onward. If you cannot do that, write back.

Craig Newman

Re: Datagrid

Posted: Fri Feb 17, 2012 5:38 am
by sturgis
Ok, so you have a tab delimited list thats going into a FORM datagrid with the first line being labels.

you can
set the dgtext[true] of group "mygridgroup" to myTabAndCRDelimitedList -- true means to use the first line as labels

Once you've done that the data should be in the datagrid. Might not be visible, but if you didn't get an error the setting of the dgtext most likely worked.
I'm assuming you adjusted the row template and have all your fields set up to receive the data. In the behavior script, the handler that fills in the data, you have to specifically state what goes where (as you mentioned)

So if you set the dgdata to the following example text

id (tab) fname (tab) lname
1 (tab) Mike (tab) smith

the keys of the internal data array should be id, fname and lname

So if you have a field in your row template named id you would
set the text of field "id" of me to pDataArray["id"] changing the field name and array key for each column you wish to display.

Save the script, select the datagrid and click the button to refresh it and hopefully your data will show up. (might have to take the check out of "fixed control height" depending on your layout and how you set stuff up.

If your data still doesn't show, I'd wonder at how your template is set up. Since I don't know if this is obvious or not, when you adjust the row template you a) select the datagrid, b) click the "row template" button in the inspector, then c) select the group in the resulting window and at the top click "edit group" If you are adding and modifying things in the template before selecting and clicking the "edit group" button, the edit is being done in the wrong place. (Probably not a problem but thought i'd point it out)

Re: Datagrid

Posted: Fri Feb 17, 2012 6:01 pm
by mwieder
you can
set the dgtext[true] of group "mygridgroup" to myTabAndCRDelimitedList -- true means to use the first line as labels
Close, but...

"true" means use the first line as column labels *AND* match those column labels up with existing column labels.

So if the first line of myTabAndCRDelimitedList is
id firstName lastName email regCode

you still won't get any date populated into the datagrid unless you've already set up those column names in the property inspector.
It's an extra step, and seems unnecessary at first, but it buys you the possibility of populating the datagrid even with columns out of order. You could, for example, have columns

email
firstname
regCode
lastName
id

and the datagrid would still populate correctly because the data would get matched to the column header text.

If you instead say
set the dgtext[false] of group "mygridgroup" to myTabAndCRDelimitedList
then the first line won't be used as a column header match and the data will populate as is.

Re: Datagrid

Posted: Fri Feb 17, 2012 6:10 pm
by sturgis
Ah k, I had seen in the original question
. The data will not be edited by the user. Only displayed. For now I was importing the text file in the properties (content) section. It asked if I had headers and I clicked yes.
So was giving an example based on the existence of headers in the data. So, on a form datagrid, if you set "headers" to false it will just populate the fields in their layer order (with all the data set up in the correct order of course) without the need to "set the text of field "whateverfield" of me to blahblahblah.." for each field in the fillindata?

Haven't messed with datagrids in a while and I swear I can't remember the dg stuff for more than a week.

Re: Datagrid

Posted: Fri Feb 17, 2012 6:17 pm
by mwieder
Haven't messed with datagrids in a while and I swear I can't remember the dg stuff for more than a week.
<g> I know that feeling well...

Re: Datagrid

Posted: Fri Feb 17, 2012 6:21 pm
by mwieder
While I'm at it, I should put in a plug here and say that if you're going to be dealing with datagrids, you *really* should look into the Data Grid Helper plugin.

http://www.runrev.com/store/product/dat ... per-1-2-0/

Re: Datagrid

Posted: Fri Feb 17, 2012 6:54 pm
by JoeZimmerman
thanks for the help everyone. I'm still having issue figuring this out. I did come across the DataGridHelper and was going to give it a try later tonight. Im still having issue though understanding some things.Here is my plan so you can see my train of thought. I've been tryig to build this app for 2 years now. i started in plain xcode and just hit too many hurtles so now im trying livecode. I want this data grid to list the info but also just list some of the items. I know a database would be the best route but i dont want to get that deep into the programming just yet. SO i was going to make different text files and have buttons load the text files into the data grid. So in theory i want to have a buttong for "monday" and it would load all the bands that played on monday into the datagrid, and so on. And if someone clicked on the row it would open a second card that dispalyed all the info for that row not just what the form showed. So thats my program in a nut shell. I could pay someone to do this for me but like i said i've wanted to do this myself and have been trying for 2 years (off and on) and just run into learning walls and this time I just want to get over it finally.

Here is my text file (sort of)
Artist (tab) Day (Tab) Time (tab) Stage (tab) Image(url)

here is what ive tried so far
1. I tried setting up the griD as a table and added the column names in the properties menu and then switched to over to "form" - would that work or will it ignore the column properties I set up once I change it to a form grid?

2. I tried setting up the form based off the sample in the Datagrid tutorial: creating-a-list-of-people. I clicked on the load file and imported my text file. It asked me when i imported if the file had headers and I clicked yes.

both of these worked fine if I switched the datagrid back to a "Table" style but I couldnt get the data to populate when i had it set to form.

Ill download the datagridhelper tonight when i get home from work and give that a shot. I really am dying to finally get this app made.

3. I havent even tackled the issue of trying to import the text file because I can't get the form to work. Once I get that hurdle done I'll need to find more examples of how to load the grid from a text file. I see the example in the lessons but I dont understand where the file is actually loaded. For someone not familiar with the code its hard to figure out. I see set the dgText [ pFirstLineContainsHeaders ] of group "Data Grid" to pText but how do I tell pText=MyFilename.txt where Myfilename.txt is my tab delimited text file.

thanks again all I really appreciate all the help

Re: Datagrid

Posted: Fri Feb 17, 2012 7:07 pm
by mwieder
Not to worry - the datagrid is probably the most complicated control in the LiveCode arsenal.
all the bands that played on monday
Well, there you go... Monday's typically a dead night for bands, so there's no data <g>.

I've been working with datagrids in table view, so I can't say much about form view or the differences. It may well be that when you change the view you have to reload the data.

And I'm hoping you really meant Artist (tab) Day (Tab) Time (tab) Stage (tab) ImageUrl

Re: Datagrid

Posted: Fri Feb 17, 2012 7:36 pm
by sturgis
Sorry for the inline responses i'm about to do, for this particular question it might be easier though so here goes. (look for #### to mark start and stop points. Also, a bit groggy today so I apologize for any huge run-on sentences and lack of proper grammar.)
JoeZimmerman wrote:thanks for the help everyone. I'm still having issue figuring this out. I did come across the DataGridHelper and was going to give it a try later tonight. Im still having issue though understanding some things.Here is my plan so you can see my train of thought. I've been tryig to build this app for 2 years now. i started in plain xcode and just hit too many hurtles so now im trying livecode. I want this data grid to list the info but also just list some of the items. I know a database would be the best route but i dont want to get that deep into the programming just yet. SO i was going to make different text files and have buttons load the text files into the data grid. So in theory i want to have a buttong for "monday" and it would load all the bands that played on monday into the datagrid, and so on. And if someone clicked on the row it would open a second card that dispalyed all the info for that row not just what the form showed. So thats my program in a nut shell. I could pay someone to do this for me but like i said i've wanted to do this myself and have been trying for 2 years (off and on) and just run into learning walls and this time I just want to get over it finally.

Here is my text file (sort of)
Artist (tab) Day (Tab) Time (tab) Stage (tab) Image(url)

here is what ive tried so far
1. I tried setting up the griD as a table and added the column names in the properties menu and then switched to over to "form" - would that work or will it ignore the column properties I set up once I change it to a form grid?
Just tried it, and no you can't set up your column info and then switch on the fly to form view.

2. I tried setting up the form based off the sample in the Datagrid tutorial: creating-a-list-of-people. I clicked on the load file and imported my text file. It asked me when i imported if the file had headers and I clicked yes.
#######When you set up the form view, did you select the datagrid, then click "row template"?
Then in the window that opens, click the group that is shown there, then click the "edit group" button, then add your fields for the text data as well as an image object for your image, and name each field and image object to match your proposed data?
(fields artist, day, time, stage. image imageurl, and set the image to the size you want it to appear and lock its size and position in the inspector so that it doesn't resize on image load.)
Also make sure to remove the field named "label" that is the default for the template. Or just rename it and use it as one of your fields.
After which, you need to click "edit group" again to leave group edit mode and then close the window that was opened when you clicked "edit row template" initially. You'll be prompted to save, do so.
At this point your template should be set up to receive the data, but you need to adjust the behavior script to actually USE the data.

With the datagrid selected click the row behavior button in the inspector. This will open up the behavior script for your form datagrid.

Find the "fillInData" handler
There is an example already there that shows how to set the text of field label (which doesn't exist anymore) So, you need a line for each item of your data that you want to display (that you created a field for)
set the text of field "fieldname from your row template" of me to pDataArray["the name that appears in the header line of your data"]

For the image I believe you can do

put URL pDataArray["the name of the column header from your text for the image"] into image "the name of the image" of me

You will have to fix a few other things too. The basic script had the field "label" that you will have changed, but there are references to it elsewhere in the script.

You will want to modify the layoutcontrol handler so that the positions of your fields and image are set on the fly as data is populated. So you'll want to change the reference to the label field, and add any changes needed to make your information display correctly.

You'll also want to look at the resetdata handler, it should be pretty obvious what to do there. (again there is an example using the label field, just add lines for each field, and "put empty into image "imagename"" and remove the label field reference.

Once you get it all cleaned up and how you want it to be, compile the script.

########


both of these worked fine if I switched the datagrid back to a "Table" style but I couldnt get the data to populate when i had it set to form.

Ill download the datagridhelper tonight when i get home from work and give that a shot. I really am dying to finally get this app made.

3. I havent even tackled the issue of trying to import the text file because I can't get the form to work. Once I get that hurdle done I'll need to find more examples of how to load the grid from a text file. I see the example in the lessons but I dont understand where the file is actually loaded. For someone not familiar with the code its hard to figure out. I see set the dgText [ pFirstLineContainsHeaders ] of group "Data Grid" to pText but how do I tell pText=MyFilename.txt where Myfilename.txt is my tab delimited text file.

thanks again all I really appreciate all the help

Once your datagrid is set up, move on to the import of data to see if it looks right. If you have a file on disk that is your tab delimited file with headers (the headers have to match the code you put into the behavior) you can use the URL keyword to get it pretty easy.

I believe you can set the dgtext[true] of group "myDatagridGroup" to URL "binfile:/path/to/text/file.txt"

Re: Datagrid

Posted: Sat Feb 18, 2012 1:48 am
by JoeZimmerman
Thanks again Sturgis. I'm going to have to step away and try some more tomorrow. I swear i followed the same steps you posted but i must be missing something as I just cannot get it to work. 1 thing I should mention that maybe causing an issue is I'm not using all the columns I imported when I create the form view. I have stuff in all the columns i mention but when i build the form i only trying to use the (artist)(time)(stage) to keep it simple at this point . does that matter? Im going to try it with a text file that has just those 3 next. I downloaded and tried the datagridhelper demo but the form builder part is locked down so it does me no good at this point.

Re: Datagrid

Posted: Sat Feb 18, 2012 2:14 am
by sturgis
Nope, shouldn't matter.

However, I just did some tests. Did you name one of your fields (in the row template) time? If so, its a reserved word, and while quoting it should get around problems, it seems that it does NOT. I could not populate the datagrid successfully until I renamed the time field. Might try it to see if that fixes it. If not I can post a working stack for you to look at and do comparisons.

When you set the dgtext of the datagrid group, does it act like there is data there but you just can't see it?
JoeZimmerman wrote:Thanks again Sturgis. I'm going to have to step away and try some more tomorrow. I swear i followed the same steps you posted but i must be missing something as I just cannot get it to work. 1 thing I should mention that maybe causing an issue is I'm not using all the columns I imported when I create the form view. I have stuff in all the columns i mention but when i build the form i only trying to use the (artist)(time)(stage) to keep it simple at this point . does that matter? Im going to try it with a text file that has just those 3 next. I downloaded and tried the datagridhelper demo but the form builder part is locked down so it does me no good at this point.

Re: Datagrid

Posted: Tue Feb 21, 2012 5:58 pm
by JoeZimmerman
I finally got a chance to look at this again. You were on the money. Once i changed that Time to TME it worked! I haven't done much programming since VB 3 back in college so I wasn't even thinking about reserved words. Thanks again for the help