getting current value from data cells

Revising my question hopefully to make more sense.

I have a 3 column table with a popup data cell and 2 buttons to add or remove rows. I want to be able to get all of the current names of the popup’s when I click on the “button” button. Currently when using this script I get the values of all columns of the row and the values are index numbers of the current value.

set the_table to table view 1 of scroll view 1 of window of the_object
		set the_table_data_source to data source of the_table
		set the_values to contents of data cells of data rows of the_table_data_source

Does anybody know how to get just the name of the current value of popup in column one of all rows (looking to build a list).

Example (“pete”,“jason”,“mike”)

Thanks!

Hi petekin,

Well, the data of a popup in a data source is stored as integer, so what I do when I get up to that is i create a property or a variable that contains the various items that I want to show in such popups, for example:

property popupItems : {"pete","jason","mike"}

and then use this to populate the popup cells at launch time:


tell table view "mainTV" of scroll view "mainSV" of window "mainWindow"
	set menuDataCell to data cell 1 of table column 1
	call method "removeAllItems" of menuDataCell
	call method "addItemsWithTitles:" of menuDataCell with parameter popupItems
end tell

Then when I want to get the values out of the data source, I do a repeat loop:

set dataSourceContents to contents of data source of table view "mainTV" of scroll view "mainSV" of window "mainWindow" as list
if (count of items in dataSourceContents) > 0 then
	repeat with currentItem from 1 to (count of items in dataSourceContents)
		set itemIntegerValue to (item 1 of item currentItem of dataSourceContents) as integer
		set (item 1 of item currentItem of dataSourceContents) to (item ((itemIntegerValue +1) of popupItems) as string
	end
end

and use the integer value (+1 because it starts at 0) of the popup contents to get the corresponding item as text from the property that was used to populate the popups in the data rows. I realize that there might be an easier way, but this way I can add or remove as many items as I want in the popup without taking care of details I don’t want to care about! :slight_smile:

Does this answer your question?

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Actually here is a faster way to do the repeat loop. With thousands of entries you cut the time in half! Plus it gets rid of the check to see if there is data in the data source:


set dataSourceContents to contents of data source of table view "mainTV" of scroll view "mainSV" of window "mainWindow" as list
repeat with currentItemRow in dataSourceContents
       set itemIntegerValue to (item 1 of currentItemRow) as integer
       set (item 1 of currentItemRow) to (item ((itemIntegerValue +1) of popupItems) as string
   end

I have tried and tried to get the names of the current menu item of the popups in my table views, but I had to resort to this way to make it work. Also, I have to make my apps in many languages, so this helps me not to deal with localization issues.

Also, I tend to create a routine to check the count of items in the table view, not only to update a count text field’s contents, but also to disable/enable the “submit” button. This way, if there is no data in the table view, the button is not available.

Browser: Safari 531.9
Operating System: Mac OS X (10.6)