tdog,
there are 2 possibilities to ask a table view for it’s selected rows:
-
tell table view "tv" of scroll view "sv" of window "main"
set sel to selected rows
end tell
gives a list of row numbers (integer) - like this:
{1, 2, 3, 4, 5, 6, 7, 8, 9}
-
tell table view "tv" of scroll view "sv" of window "main"
set sel to selected data rows
end tell
gives a list of references to the tv’s data source: like this:
{data row id 7 of data source id 4, data row id 8 of data source id 4, data row id 9 of data source id 4, data row id 10 of data source id 4, data row id 11 of data source id 4, data row id 12 of data source id 4, data row id 13 of data source id 4, data row id 14 of data source id 4, data row id 15 of data source id 4}
in both cases it is possible to reset / set the selection by giving it such a list as parameter:
tell table view "tv" of scroll view "sv" of window "main"
set selected rows to {1,2,3,4,7,8,9}
set selected data rows to {data row id 7 of data source id 4, data row id 8 of data source id 4, data row id 15 of data source id 4}
set selected rows to {} -- no selection
set selected data rows to {} -- no selection
end tell
The big advantage of using ‘data rows’ is, that this references remain after deleting item(s) (while when deleting a row of a table view any higher row number will be decremented by 1) - So if you for example want to delete a single item of the selected rows and want the rest to remain selected you could do it like so:
tell table view "tv" of scroll view "sv" of window "main"
set sel to selected data rows
tell data source
delete item 3 of sel
end tell
set selected data rows to ((items 1 thru 2 of sel) & (items 4 thru -1 of sel))
end tell
In no case there should be a difference between a ‘Cmd-A’- and a clicked selection - maybe you could post some code?
Hope that helps …
D.