I have a table view using a data source, an NSPopUpButtonCell in the first column and I’m populating the menu with 4 values. What I need to do is get the value (title) of the menu after the user has selected one of the 4 choices. The only handler option in Interface Builder is On Clicked. Using this I was able to get the 0 based index of the menu. However, the first time I select a different menu option I get the previously selected index number.
Example, I select first menu item and get index 0, then I select the second menu item and get 0 again but then each subsequent selection of the second menu item returns 1 as expected. So every time I choose a different menu item I get the previous index on the first try.
Here’s the on clicked handler:
if name of theObject is "PopUpButtonCell" then
set theDataSource to data source of table view "table1" of scroll view "table1" of window "window1"
set menuTitle to (get contents of data cell 1 of data row 1 of theDataSource)
end if
Is there a better way to get the contents of the menu after a user has selected something?
Brilliant Jacques! That worked as planned. The next thing I need to figure out is how to take the value thats returned (menuTitle) and use that to set the contents of the next data cell. What I’d like is for the user to be able to select an option from the menu and have that value placed in cell 2.
I tried:
if table column 1 of theObject is tableColumn then
set menuTitle to call method "itemTitleAtIndex:" of (data cell 1 of table column 1 of theObject) with parameter theValue
set contents of data cell 2 of data row theRow to menuTitle
end if
I know it’s possible I just can’t figure out the syntax to target that cell.
Heh, I should have tried a few more things myself before posting. I was able to get it to work with:
if table column 1 of theObject is tableColumn then
set menuTitle to call method "itemTitleAtIndex:" of (data cell 1 of table column 1 of theObject) with parameter theValue
set selectedDataRows to selected data rows of table view "table1" of scroll view "table1" of window "window1"
tell window "window1"
set contents of data cell 2 of (item 1 of selectedDataRows) to menuTitle
end tell
end tell
Thanks again for your help Jacques, that helped immensely!