Page 1 of 1
How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 5:07 am
by shawnblc
I have a datagrid that has a linked pdf file. I'd like to be able to open the pdf file when the file is clicked on in the data grid. I see the open file "etc.txt" in the dictionary. But don't think that's actually what I'm looking for. Any help is appreciated.
I have this (using DBlib):
Code: Select all
put field "fldFile" into myRecord["fldFile"]
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 12:43 pm
by Klaus
Hi Shawn,
to open a document just like doubleclicked in the desktop/Finder, do this:
...
launch document "path/to/your doc.pdf"
...
Best
Klaus
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 2:10 pm
by shawnblc
I appreciate it Klaus.
Still can't get it working, but it's probably because I didn't accurately describe what I'm trying to accomplish.
I have a dgData grid with 3 columns. One of those columns have the column title of fldFile. I'd like to launch the file when a fldFile row is hilited. All the files are pdf files.
Right now on my dgData grid I have this
Code: Select all
on mouseUp
launch the selectedText of field "fldFile"
end mouseUp
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 2:28 pm
by Klaus
Hi Shawn,
hmm, where's the problem, just do it accordingly:
Code: Select all
on mouseUp
put the selectedText of field "fldFile" into tFile
launch document tFile
end mouseUp
Best
Klaus
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 2:35 pm
by shawnblc
Hmmm.
This is what I changed it to.
Code: Select all
on mouseUp
launch document field "fldFile"
end mouseUp
Then changed to your code above. I get the same result, which isn't opening the PDF file, but no error, it's opening the folder where my LC project is saved. I'm still working on it

and reading.
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 3:00 pm
by Klaus
Hi Shawn,
shawnblc wrote:Code: Select all
on mouseUp
launch document field "fldFile"
end mouseUp
Then changed to your code above. I get the same result, which isn't opening the PDF file, but no error,
it's opening the folder where my LC project is saved. I'm still working on it

and reading.
OK, you should check the result to get a hint on what might go wrong:
Code: Select all
...
launch document (field "fldFile")
if the result <> EMPTY then
answer "Error:" && the result
end if
...
Best
Klaus
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 3:07 pm
by shawnblc
Thanks. I think I'll be able to figure it out with what help you've given me. I appreciate it. I'll update this thread. Thank you Klaus.
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 3:55 pm
by shawnblc
When I do this ----> it works.
Code: Select all
on mouseUp
launch document "/Users/Shawn/Dropbox/myPDF.pdf"
end mouseUp
when I do this it does not work. hmmmm.
Code: Select all
on mouseUp
put the selectedText of field "fldFile" into tFile
launch document tFIle
end mouseUp
OR
on mouseUp
launch document field "fldFile"
end mouseUp
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 4:23 pm
by Klaus
Hi Shawn,
hmmmm, are you sure that in tFile is really a valid path to your PDF document -> "/Users/Shawn/Dropbox/myPDF.pdf"?
...
## Do something like this:
answer tFile
answer (there is a file tFile)
...
What does "the result" tell you?
Best
Klaus
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 4:36 pm
by shawnblc
I get fldFile and False
Here's a snap of my data grid. The URL to the PDF file is valid and will open as described above but not when referenced with fldFile or tFile.
This works. In fact I can reference any PDF file like below and it will work.
Code: Select all
on mouseUp
launch document "/Users/Shawn/Dropbox/Apple Store.pdf"
end mouseUp
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 5:22 pm
by Klaus
AHA, Datagrid!
OK, we are getting nearer:
I get fldFile and False
So this is in fact a problem of pulling the correct data out of your datagrid!
Where did you put the "mouseup" script? In the group script?
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 5:25 pm
by shawnblc
Klaus wrote:AHA, Datagrid!
OK, we are getting nearer:
I get fldFile and False
So this is in fact a problem of pulling the correct data out of your datagrid!
Where did you put the "mouseup" script? In the group script?
In the data grid on mouseUp. I have hilited box ticked in the properties.
What I'm trying to accomplish is basically like a HTML table where the file would be hyperlinked to the file and open in your pdf viewer. This has me stumped. I must've tried a hundred variations.
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 5:52 pm
by Klaus
OK, datagrids are highly cool but complex beasts, so you need to do someting like this in the "mouseup" script.
Datagrids hold their content in a multidimensional Array (the dgData of grp "your datagrid") ,
which makes it easy to address your "fields" directly, see below:
Code: Select all
on mouseup
## Get the selected index/line:
put the dgHilitedindex of me into pHilitedIndex
## Get the array for the selected "row":
put the dgDataOfIndex[pHilitedIndex] of me into theDataA
## get the key assocciated with your field "fldFile":
put theDataA["fldFile"] into tFile
if there is a file tFile then
launch document tFile
else
answer "File missing:" & CR & tFile
end if
end mouseup
Best and merry cristmas
Klaus
P.S.
Load the complete docs (PDF) for datagrids here, not really easy to handle, but powerful!
http://lessons.runrev.com/m/datagrid
Re: How to open a PDF file that's linked in a data grid?
Posted: Tue Dec 25, 2012 5:58 pm
by shawnblc
Wow Klaus. Thank you! That worked! I have a lot to learn, but I'm having a lot of fun! I'll have to make sure I save all of the snippets of code that you've provided. I'm sure that they'll come in handy on this LC journey. Thank you and have a great day!