How to insert images dynamically into a DataGrid table ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
Fred_29
Posts: 2
Joined: Tue Sep 04, 2018 9:21 pm

How to insert images dynamically into a DataGrid table ?

Post by Fred_29 » Thu Sep 06, 2018 9:34 pm

Hello,
I'm a complete beginner in Livecode and I didn't solve my problem about DataGrid...

After a query from a database, I get tab delimited data in several rows and columns; the numbers of columns and rows may change depending of the query but each data represents a few words or "1".
I don't know if it's possible to create a Datagrid table dynamically from this tab delimited data and in each cell containing "1" I'd like to get the image associated with the corresponding file : "Image_1.jpg".

I used the LiveCode lesson "How do I create a Datagrid dynamically from tab delimited data" to populate my DataGrid and adjust some properties but I don't know how to create dynamically an image into a cell from this DataGrid and then how to assign it to a file or an image in a card.

I've tested some codes but without any results, or with errors like in my last one :

Here is a part of my last code :
In the section "create row template", I've created a button called "flag" and then I've grouped it with the other components

Code: Select all

--create row template : 
put the name of this stack into tMainstack
put "Data Grid Templates" && the seconds into tName
create invisible stack tName
set the mainStack of stack tName to tMainstack
go stack tName
create card
create field "label"
create graphic "Background"
create button "flag"
group field 1 and graphic 1 and button "flag"
set the name of last group to "Row Template"
go stack tMainstack
I insert my image by its ID in the Stack, in the Data Grid Template :

Code: Select all

-- Add images : 
copy image id 8729 to stack tName
...

--point datagrid to template
set the dgProp["Row Template"] of group "my Datagrid" to the long id of group "Row Template" of stack tName
...

--add data : 
put true into tFirstLineIsNames
set the dgText[tFirstLineIsNames] of group "my DataGrid" to tData

I've assigned the icon of the created button to my image :

Code: Select all

set the icon of button "flag" to the id 8729
and then I've got an error: " (Chunk: error in object expression) near "8729", char 37 "

Is it the right way for such a task ?

Thank you in advance.

Fred

Klaus
Posts: 10386
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to insert images dynamically into a DataGrid table ?

Post by Klaus » Fri Sep 07, 2018 2:04 pm

Hi Fred,

welcome to the forum!

I never created a datagrid via script and will NEVER do, at least not for a FORM datagrid, since there is so (too) much to take care of.
And I use LC and its ancestors for almost twenty years now and I'm really no dumbhead!

The lesson you mentioned if made for datagrids of type TABLE (= text only) and I am sure this is not easily applicable, if at all, for a FORM.

Some hopefully helpful hints:
1. If you do

Code: Select all

...
create card
create field "label"
create graphic "Background"
create button "flag"
...
These objects are created at the SAME position/LOCation.
Try this in a button in a fresh/new stack and see what I mean.
So you need to also layout the objects correctly in yout "template".

2.

Code: Select all

...
copy image id 8729 to stack tName
...
After copying the image it has a different ID in stack tName!

3. The DGTEXT is meant for datagrids of type TABLE.
But since you want to have Buttons and Graphics in your DG, this should be of type FORM.

4.

Code: Select all

...
put true into tFirstLineIsNames
set the dgText[tFirstLineIsNames] of group "my DataGrid" to tData
...
Is this really true that the first line of your data contain the NAMES of the datagrid rows?
Again, this (the dgtext) is more meant for TABLE datagrids.

5.

Code: Select all

...
set the icon of button "flag" to the id 8729
...
The correct syntax is:

Code: Select all

...
set the icon of button "flag" to 8729
...
No THE and no ID.
But see above, this will not work due to the different ID of the copied image.

I highly recommend to work through the Datagrid PDF with all its examples, find it here:
http://lessons.livecode.com/m/datagrid
The TINY link on the left under "Topics".

Datagrids are the most complex objects EVER in LC, but unfortunately also the most attractive one, which also attracts new users and makes them despair very soon.

Even I need to look up the above mentioned PDF from time to time to refresh my knowledge of the complex scripts needed.

Best

Klaus

Klaus
Posts: 10386
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to insert images dynamically into a DataGrid table ?

Post by Klaus » Fri Sep 07, 2018 2:25 pm

Can't you create a datagrid manually in LC and the we take care of how to populate it with data, which is still complex enough?

bogs
Posts: 2282
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to insert images dynamically into a DataGrid table ?

Post by bogs » Fri Sep 07, 2018 4:26 pm

Klaus wrote:
Fri Sep 07, 2018 2:04 pm
I highly recommend to work through the Datagrid PDF with all its examples, find it here:
http://lessons.livecode.com/m/datagrid
The TINY link on the left under "Topics".
Boy, no kidding :shock:
Selection_003.png
REALLY tiny !
Hoping to possibly save you some eye strain, you can just click this link to get the pdf directly, or, if you don't trust links you can also just open the dictionary (vers. 8.x up) and go to the 'Guides' section to have all this outlined directly in the Lc IDE.
Selection_004.png
Lc Dictionary Guide...
Image

Fred_29
Posts: 2
Joined: Tue Sep 04, 2018 9:21 pm

Re: How to insert images dynamically into a DataGrid table ?

Post by Fred_29 » Mon Sep 10, 2018 3:23 pm

Hi Klaus and Bogs,

Thank you very much for your help.
During many years I was programming with Director ( from Macromedia ) and after it disappeared I had to move to another programming language. I choose LiveCode because it seems to be powerful and suitable for the applications I'd like to create, however I'm confused with arrays and DataGrid...
Klaus wrote :
Can't you create a datagrid manually in LC and the we take care of how to populate it with data, which is still complex enough?
I think it's the solution I have to follow, I will spend more time to read again the DataGrid pdf you and Bogs mentionned and then I'll post again if I don't know how to populate my Datagrid correctly.

I thank you again for the time you spend to answer my question.

Bye

Fred

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”