Importing CSV file contents into DataGrid

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
PeterG
Posts: 168
Joined: Sat Jun 29, 2013 7:56 pm

Importing CSV file contents into DataGrid

Post by PeterG » Tue Oct 31, 2017 11:26 am

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
Attachments
Screen Shot 2017-10-31 at 11.34.32 AM.png
Screen Shot 2017-10-31 at 12.19.27 PM.png

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Importing CSV file contents into DataGrid

Post by MaxV » Tue Oct 31, 2017 11:51 am

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
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply