Page 1 of 1
Getting values from Selected Datagrid row
Posted: Tue Sep 17, 2019 2:10 pm
by gagsoft
Hi guys
I get "group "MyGrid": execution error at line n/a (Object: object does not have this property)" from the datagrid.
The goal is to edit a record.
Here is the code:
on selectionChanged
put the hilitedline of me into tLine
// put the dgline of me into tLine
Answer tLine
put item 1 of line tLine of me into field "id"
put item 2 of line tLine of me into field "Client"
put item 3 of line tLine of me into field "Contact"
put item 4 of line tLine of me into fld "Phone"
put item 5 of line tLine of me into fld "Issue"
put item 6 of line tLine of me into fld "Issuedate"
put item 7 of line tLine of me into fld "Remedy"
put item 8 of line tLine of me into fld "RemedyDate"
end selectionChanged
Would appreciate any pointers here as am still testing the waters here
Re: Getting values from Selected Datagrid row
Posted: Tue Sep 17, 2019 2:17 pm
by Klaus
Hi gagsoft,
well almost:
Code: Select all
...
## FIELDS do have this property -> hilitedline
## GROUPS (datagrids) do NOT!
## put the hilitedline of me into tLine
## This is the one:
put the DGhilitedline of me into tLine
...
Best
Klaus
Re: Getting values from Selected Datagrid row
Posted: Tue Sep 17, 2019 2:23 pm
by gagsoft
Hi Klause
Many thanks
Much appreciated
Re: Getting values from Selected Datagrid row
Posted: Tue Sep 17, 2019 2:29 pm
by Klaus
Klaus, without an E!
If in doubt, just copy and paste my name.
Re: Getting values from Selected Datagrid row
Posted: Tue Sep 17, 2019 5:09 pm
by Zryip TheSlug
Hi Gagsoft,
Have a look to this lesson:
http://lessons.livecode.com/m/datagrid/ ... -or-column
Note the dghilitedline is returning the number of the selected line, not the content data of the corresponding row.
You need to deal with the array notation for that.
Code: Select all
put the dghilitedline of me into tLine
put the dgDataOfLine[tLine] of me into theDataA
put theDataA["id"] into field "id"
put theDataA["client"] into field "client"
etc
Note each keys of the array returned by the dgDataOfLine property is columns names of your datagrid: id, client, contact, etc
Best Regards,
Re: Getting values from Selected Datagrid row
Posted: Wed Sep 18, 2019 7:17 pm
by gagsoft
Hi guys
I tested this:
on selectionChanged
put the DGhilitedline of me into tLine -- This works
Answer Tline
put the dgDataOfLine[tLine] of me into theDataA
//The following does not yield anything
put theDataA["id"] into field "id"
put theDataA["client"] into field "client"
end selectionChanged
Am I missing something here?
Re: Getting values from Selected Datagrid row
Posted: Wed Sep 18, 2019 7:40 pm
by Zryip TheSlug
This should work. Do your columns are named "id" and "client"? Don't confuse column name and column label.
Try with a fresh datagrid and three new columns:
Both codes:
Code: Select all
on selectionChanged
local tLine, theDataA
put the dghilitedline of me into tLine
put the dgDataOfLine[tLine] of me into theDataA
put theDataA["col 1"] into field "col1"
put theDataA["col 2"] into field "col2"
put theDataA["col 3"] into field "col3"
end selectionChanged
And the more optimized (because selectionChanged is receiving two parameters sent by the datagrid API: the clicked index and the previous selected index)
Code: Select all
on selectionChanged pHilitedIndex, pPrevHilitedIndex
local theDataA
put the dgDataOfIndex[pHilitedIndex] of me into theDataA
put theDataA["col 1"] into field "col1"
put theDataA["col 2"] into field "col2"
put theDataA["col 3"] into field "col3"
end selectionChanged
Note, this code is something similar to the example for the selectionChanged readable in the datagrid API (topic = "Messages Sent"):
http://lessons.livecode.com/m/datagrid/ ... a-grid-api
Are working well. I'm using this with different datagrids.
Re: Getting values from Selected Datagrid row
Posted: Wed Sep 18, 2019 8:20 pm
by gagsoft
Thank you guys
voila.. It works like a charm.
Klaus my apologies about the typo☺...will not happen again.
Many thanks