How to populate a table column with data from a column in a CSV file

I am trying to populate a column in a table view with the data from a column in a CSV file but I cannot get it to work.

In Interface Builder, I have given the following elements the following AppleScript names:

window 1 – MainWindow
scroll view 1 – ScrollView
table view 1 – TableView

Cells/Columns:
1 – SelectCol
2 – NameCol
3 – StatusCol
4 – MailCol
5 – BalanceCol

Here’s the script:

on awake from nib theObject
	set CharData to (read file "HFS:Path:To:File.csv")
	set theDataSource to make new data source at end of data sources with properties {name:"CharDataSource"}
	tell theDataSource
		make new data column at end of data columns with properties {name:"SelectCol"}
		make new data column at end of data columns with properties {name:"NameCol"}
		make new data column at end of data columns with properties {name:"StatusCol"}
		make new data column at end of data columns with properties {name:"MailCol"}
		make new data column at end of data columns with properties {name:"BalanceCol"}
	end tell
	tell data source "CharDataSource"
		repeat with a from 2 to (count (paragraphs of CharData))
			set theRow to make new data row at end of data rows
			tell theRow
				set contents of data cell "NameCol" of theRow to word 1 of paragraph a of CharData
			end tell
		end repeat
	end tell
end awake from nib

When I build and run, the interface comes up, but nothing happens. I’ve looked at numerous tutorials, and I’m still not sure what’s wrong here

I believe you need to “hook up” your data source to the table view. Off the top of my head it’s something like

set datasource of TableView of ScrollView of window 1 to "CharDataSource"

Thanks SuperMacGuy, but I still get nothing in the table. Curiouser and curiouser. FYI, this is how is now reads:

on awake from nib theObject
	set CharData to (read file "HFS:Path:To:File.csv")
	set theDataSource to make new data source at end of data sources with properties {name:"CharDataSource"}
	set data source of table view "TableView" of scroll view "ScrollView" of window "MainWindow" to "CharDataSource"
	tell theDataSource
		make new data column at end of data columns with properties {name:"SelectCol"}
		make new data column at end of data columns with properties {name:"NameCol"}
		make new data column at end of data columns with properties {name:"StatusCol"}
		make new data column at end of data columns with properties {name:"MailCol"}
		make new data column at end of data columns with properties {name:"BalanceCol"}
	end tell
	tell data source "CharDataSource"
		repeat with a from 2 to (count (paragraphs of CharData))
			set theRow to make new data row at end of data rows
			tell theRow
				set contents of data cell "NameCol" of theRow to word 1 of paragraph a of CharData
			end tell
		end repeat
	end tell
end awake from nib

You append a row of data to a data source:

append theDataSource with {{someColumn:someData, anotherColumn:moreData, lastColumn:lastData}}

There is plenty of information here on how to access/append rows of a data source.


		repeat with a from 2 to (count (paragraphs of CharData))
                            make new data row at end of data rows of theDataSource
                            set data source of table view "TableView" of scroll view "ScrollView" of window "MainWindow" to contents of theDataSource
				set contents of data cell "NameCol" of data row a of data source of table view "TableView" of scroll view "ScrollView" of window "MainWindow" to word 1 of paragraph a of CharData

		end repeat

Thanks, I’ll try that out tomorrow.