Page 1 of 1

Importing CSV file contents into DataGrid

Posted: Tue Oct 31, 2017 11:26 am
by PeterG
Hi Guys
Got this code that I want to use to import the contents of into a data grid:
On ReadDataFile
answer file "Select a file"
put URL ("file:" & it ) into tFileContents
Put tFileContents into field "text" on Card "TrnHist"
put line 1 of tFileContents into tColumnTitles ## Creates Columns from the contents of the CSV's first line
replace comma with return in tColumnTitles
set the dgProp["columns"] of group "AppData" on Card "TrnHist" to tColumnTitles
delete line 1 of tFileContents
replace "*" with tab in tFileContents
Put tFileContents into field "text" on Card "TrnHist"
set the dgText of group "AppData" on Card "TrnHist" to tFileContents
While tracing the code I get no errors and it puts the contents in the text field as well as replacing the "*" with a tab. But it does not put it in the datagrid.
Se attached images.

Any pointers would be appreciated.
Peter G

Re: Importing CSV file contents into DataGrid

Posted: Tue Oct 31, 2017 11:51 am
by MaxV
Try just this:

Code: Select all

set the dgText[true] of group "AppData" on Card "TrnHist" to tFileContents
See: http://livecode.wikia.com/wiki/Datagrid_API