Intercepting Pop Up Selections

Hi All,
I think I’m missing or forgotten something fundamental. I’ve got a pop up for which I’ve bound the selected index to the property theIndex. I’m intercepting the setting of theIndex so I can run some code that depends on the selection. One thing I’d like to do is to have the ability to change the selected index to a set value under certain conditions (i.e., ignoring the users selection), but it seems the pop up is ignoring my changing of value of theIndex.

For testing, if I try the following:


on setTheIndex_(newLabel)
		set my theIndex to 0
end setTheIndex_

I’m expecting the pop up to be set to its first item regardless of what the user chooses. The handler does get called, and theIndex does get set to 0, but the selections in the pop up does not match theIndex. Any help would be greatly appreciated.

Did you try the method “synchronizeTitleAndSelectedItem()” ? Its description sounds like it would do what you want.

Ric

After edit: I tried "synchronizeTitleAndSelectedItem(), and it din’t work. I’m not sure what’s going on here, because if you do “set my theIndex to 3” in the applicationWillFinishLaunching method, it sets the selection properly, but not when you do it inside the setTheIndex method. You can however, do what you want by using the selectItemAtIndex_ method inside your setTheIndex method.

Thanks for the help. I found an awkward work around which I wasn’t very happy with, so I’ll take a look at selectItemAtIndex_. For academic purposes, does anyone know why we’re seeing this behavior?

Try separating the property and the binding key. So if your property is theIndex, bind to, say, popupIndex, then implement:

on popupIndex()
return theIndex
end

on setPopupIndex_(x)
set my theIndex to x -- (or whatever)
end

Thanks for the replies. It initially looked like selectItemAtIndex_ was working, but the pop up exhibited some strange behavior if it was used again. I still have to try what Shane suggested (for future reference), but I was able to set the index outside of the setIndex_ handler. Thanks again.