datagrid joy

Moderators: heatherlaine, kevinmiller, robinmiller, Zryip TheSlug

Post Reply
paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

datagrid joy

Post by paulalsmith1000 » Wed Aug 14, 2019 7:02 pm

Hi Anyone

Once again I have a question?

I am having a strange problem with a dg form.

I think I understand the mechanics now,but it would seem not entirely.

Basically, I have several rows in this page (see attached) with data from a db (all this works fine), Also I think I understand how to save it back again. The odd bit is as follows;

if I tick the checkbox in row 1 then it also ticks the checkbox in row 4??

likewise if I disable the scrolling list field when the check box is ticked in row 1, it does the same in row 4???

I have no idea why this is, but I presume it has something to do with the syntax of what I put into the checkbox script,

Any help, again would be smashing

Kind regards

Paul
Attachments
Screenshot from 2019-08-14 19-00-39.png

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

Re: datagrid joy

Post by Klaus » Wed Aug 14, 2019 7:39 pm

Hi Paul,

it may help if you show us the syntax of what you put into the checkbox script! 8)
And maybe also your "fillindata" handler.


Best

Klaus

paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

Re: datagrid joy

Post by paulalsmith1000 » Wed Aug 14, 2019 10:23 pm

Hi Klaus

please see the script below -

fill in data

on FillInData pDataArray

set the text of field "species" of me to pDataArray["species_identified"]
set the text of field "scroll_list" of me to tspecies_options
put pDataArray["species_image"] into timage
put base64decode(timage) into timage2
set the text of image "image" of me to timage2
set the text of field "rowid" of me to pDataArray[rowid]

end FillInData

checkbox
when checked (using on mouseup) the script would put the selected text from the scrolling list into a variable, then check if it was empty, if empty it would save the contents of the species field to the DB, if not it would save the variable (this is so someone could confirm the species name or correct it), unfortunately I deleted most of it to try and find the problem, but the end result after the above would be something like

disable me
disable species
etc...

to grey-out the row to visually show the person to move on to the next row

Many thanks for your help

Kind regards

Paul

paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

Re: datagrid joy

Post by paulalsmith1000 » Thu Sep 05, 2019 7:40 pm

Hi Klaus

Could you shed some light on the above strangeness? I have uploaded the whole stack which might help.

There are 2 datagrids in the stack.

The first one (fav picture) where the user is asked to select an image (which is then saved to the DB) works fine in the sense that it saves the image selected as it should when you double click "click to save".

But when I added "disable me" to the script of the "click to save" button it behaves very oddly in the sense that it also disables some of the other rows in the datagrid.

The second one (confirm species) has the same problem.

If you could possibly shed any light on this I would be very grateful, as I'm desperate to finish this and have no idea where to start.

Kind regards and thanks

Paul

**just tried to upload it but it wont accept the livecode file type*** if you could tell me what you need I will upload it***

in the meantime:-

The button script is

global tDatabaseID
#global tDatabasePath

on mousedoubleUp

databaseConnect

answer "are you sure this is your favourite picture?" with "Yes" or "No" titled "Confirmation"
if it is "yes" then
disable me
answer "thankyou picture saved"
takeImageFromDatagrid



else
answer "please choose another picture"
end if


end mouseDoubleUp



command takeImageFromDatagrid

put the dgHilitedLines of group "myfavpic_datagrid" into theLine
put the dgDataOfLine[theLine] of group "myfavpic_datagrid" into theDataA
put theDataA["species_image"] into timage2 --this I assume is the Base64Encoded data, not the binary
#put theDataA["rowid"] into tRowID
put "UPDATE survey_results SET favourite_picture = :1 WHERE rowid =1" into tSQL
--the WHERE clause is important or else this will affect ALL the rows in the table.

--alternative version without placeholder:
--put "UPDATE survey_results SET favourite_picture = '" & tImage2 & "' WHERE rowid =" & tRowID into tSQL
-- note the single quotes included in the literal string contained in the double quotes above, which will be needed to surround the tImage2 data

revExecuteSQL tDatabaseID, tSQL, "timage2"

--now save out fav picture to file
put base64decode(timage2) into timage3
set the text of image "pic_to_save" to timage3
put the image "pic_to_save" into timage4
set the defaultFolder to specialFolderPath("external documents") & "/" & "The Rockpool Project Surveys" & "/" & tfieldsurveyid && tfieldpname & "/" & "images"
put timage4 into URL ("binfile:Fav_picture.jpg")


end takeImageFromDatagrid


command databaseConnect
if tDatabaseID is a number then
answer "the database connection was successful, your connection id is" && tDatabaseID
else
answer "Unable to connect to the database, no existing connection"
end if
end databaseConnect


And the fill in data script is

-- This script defines the behavior of your data grid's custom template. This behavior
-- only applies to 'forms' and not 'tables'.

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.


set the text of field "species" of me to pDataArray["species_identified"]
#set the text of field "gps" of me to pDataArray["gps_location"]
#set the text of image "image" of me to pDataArray["species_image"]
put pDataArray["species_image"] into timage
put base64decode(timage) into timage2
set the text of image "image" of me to timage2
set the text of field "rowid" of me to pDataArray[rowid]


end FillInData


on LayoutControl pControlRect, pWorkingRect
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.
-- The working rect is defined area of the control you can safelt use.
-- Use this rect to make sure your controls don't overlap with any edit mode controls.

-- Example:
#put the rect of field "Label" of me into theFieldRect
#put item 1 of pWorkingRect into item 1 of theFieldRect
#put item 3 of pWorkingRect - 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 "Label" of me to empty
end ResetData


on PreFillInData
-- Sent right before new data is going to replace existing data in the control
end PreFillInData


setprop dgHilite pBoolean
-- This custom property is set when the highlight of your custom template has
-- changed. By default the "Background" graphic will be highlighted for you.
-- You only add script here if you want to further customize the highlight.

-- Example:
if pBoolean then
set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundColor of me to empty
end if
end dgHilite


getprop dgDataControl
-- Required by library so that it can locate your control.
return the long ID of me
end dgDataControl


on mouseDoubleUp pMouseBtnNum
local theKey

-- Example of how to edit the contents of a field.
-- By passing the index of the record associated with copy of this template being displayed and
-- a key (array key) the data grid will automatically save the changes the user
-- makes and refresh the UI by calling FillInData and resizeControl.
if pMouseBtnNum is 1 then
if the dgProps["allow editing"] of the dgControl of me then
switch the short name of the target
case "Label"
put "Label 1" into theKey
EditFieldText the long ID of the target, the dgIndex of me, theKey
break
end switch
end if
end if

pass mouseDoubleUp
end mouseDoubleUp

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

Re: datagrid joy

Post by Klaus » Thu Sep 05, 2019 7:43 pm

Hi Paul,

ZIP the stack, then you can upload it here.


Best

Klaus

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: datagrid joy

Post by Zryip TheSlug » Thu Sep 05, 2019 8:22 pm

Paul,

For datagrids, the strategy is to have all the scripts inside the row behavior. So instead to place your script in each buttons, you have to place it in the same location than the fillInData handler. Then for each button you have to test if this the right one and script the action it must do.

Example for two check boxes "new button" and "new button2" linked to "data 1" and "data 2" keys:

on mouseUp pTheButton
if (pTheButton is 1) then
switch the short name of the target
case "New button"
SetDataOfIndex the dgIndex of me, "data 1", the hilited of button "New button" of me
break
case "New button2"
SetDataOfIndex the dgIndex of me, "data 2", the hilited of button "New button2" of me
break
end switch
end if
end mouseUp

By the way, I have nothing against question about datagrids, but you must know the "Data Grid Helper Forum" is dedicated to the third party plugin I created for helping with datagrids, named "Data Grid Helper" or "DGH". Among other things DGH is capable to create ready to use scripts for datagrid form and table at least in the level you can understand what is required in the row behavior script.

So, we must waiting for question about DGH in this forum and not about the datagrid control itself. Be sure, if you are posting your questions about datagrids outside this forum, you have more chance to get answers.
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

Re: datagrid joy

Post by paulalsmith1000 » Sat Sep 07, 2019 6:58 pm

Hi Klaus

Please find attached.

Kind regards

Paul
Attachments
RPv.6.0.zip
(220.35 KiB) Downloaded 354 times

paulalsmith1000
Posts: 58
Joined: Sat Jun 15, 2019 10:09 am

Re: datagrid joy

Post by paulalsmith1000 » Sat Sep 07, 2019 7:02 pm

Hi Zryip TheSlug

I will try what you said.

I presume that means that I should write the scripts for the buttons etc... in the fill in data script.

Kind regards

Paul

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: datagrid joy

Post by Zryip TheSlug » Wed Sep 11, 2019 2:16 pm

paulalsmith1000 wrote:
Sat Sep 07, 2019 7:02 pm
Hi Zryip TheSlug

I will try what you said.

I presume that means that I should write the scripts for the buttons etc... in the fill in data script.

Kind regards

Paul
Paul,

What you are calling the FillInData script is the row behavior script of the datagrid form. This behavior script contains the FillInData handler, mouseDoubleUp, etc. So yes, you have to manage the mouseUp of your buttons at the same level of the FillInData handler.


Best Regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

Post Reply

Return to “Data Grid Helper”