Problem with sorting data source

I have an ASS project that I’ve been working on for about two weeks. It was working well until I tried to add some sorting to my data source. I used to have two columns of data, but I just added a third and want to sort the data by this third column. When I run the app it will work fine for a couple of loops, but then it starts to get a little crazy, acts like it locks up.

Here is the code in question…

set theDataSource to data source "datasource"
delete every data row of theDataSource
		
make new data column at end of data columns of theDataSource with properties {name:"FileName"}
make new data column at end of data columns of theDataSource with properties {name:"FilePath"}
make new data column at end of data columns of theDataSource with properties {name:"ModDate", sort order:ascending, sort type:alphabetical, sort case sensitivity:case sensitive}
		
set theCount to count of items in myNames
		
tell kMainWindowRef
	set contents of text field "date" to theDate
	set contents of text field "time" to theTime
	set contents of text field "count" to theCount
end tell
		
repeat with i from 1 to theCount
	set theDataRow to make new data row at end of data rows of theDataSource
	set contents of data cell "FileName" of theDataRow to item i of myNames
	set contents of data cell "FilePath" of theDataRow to item i of myPaths
	set contents of data cell "ModDate" of theDataRow to item i of ModDates
end repeat

set sorted of theDataSource to true
set sort column of theDataSource to data column "ModDate" of theDataSource

If I comment out the "set sorted of theDataSource to true, it goes back to working as well as it used to. The only thing I can think is that the data is being displayed in my table, then it is having to “update” the display based on the sort and causing a “display” problem.

Any thoughts on how I can correct this?

Thanks,
Dave

I figured it out. I was using this to get the selected row.

set dataXY to data rows of data source of theObject
tell item (selected row of theObject) of dataXY to set {theName, thePath} to {contents of data cell "FileName", contents of data cell "FilePath"}

I changed it to this.

set {theName, thePath} to {contents of data cell "FileName" of clicked data row of theObject, contents of data cell "FilePath" of clicked data row of theObject}

and now I’m getting the expected results. Notice the difference in the statement “clicked data row” rather than “selected row

Thanks,
Dave

OK, I take it back, that wasn’t actually my problem. I’m still having the same issue.

here is the error code I get.