Combo Box Item with title and id?

Is it possible to add a new combo box item that has a title and an ID? I can’t just go the “current item of combo box” path because I’m regenerating the contents of later drop downs based on earlier selected values and they aren’t sequential.

What I would like to end up with is, the user selects an item from a drop down, the unique ID for that Item (one that I’ve provided during the creation) is returned.

Any thoughts?

I have done this before, and I do it the hard way, since I could not figure out any other method. I design a set of handlers to create, append, and analyze records for the different combo box items, then turn the records into lists for insertion into the combo boxes. The good thing about AS records is that they have id properties available to use, and I believe they auto-increment (it has been awhile since I made something new). As long as each title is unique, and is assigned an id in record format, you can sort the lists any way you want, and still get the id number (when the user selects an item) by sending it to your analysis handler.

A second way I have done this (although it is certainly not neat or crisp) is to go from using a combo box to a 2 column table view; one column holds the title, the other holds the id number. You have to use one of those irritating call method thingies to get the data back, and you have to tolerate an ugly interface, but for personal projects, it has worked pretty quickly for me, once I get the code settled out.

Hope this helps,

HI Craig,
Thanks for the response. Is it possible to get an example of the first idea? I thought by default combo box items had the ability to have a title and a unique ID assigned to them upon creating them.



You can download my PalmSchool project and take a look at it. And, although Palm Desktop works with Leopard on any Mac, my application does not, unless it is running on a non-Intel Mac. (I don’t know why that it is.)

Anyway, Here are some guideposts to my amateurish script (PalmSchool.applescript)

–Palm Desktop provides ID numbers for all categories, but does not make them easily accessible. The first two global variables will hold individual and category ID list information (chosen_category_ID, all_Cats).

–The will open handler has a Palm routine to get all the category id and name data into a 2-item list (set end of all_Cats to {b’s id, b’s name}). That is a global list, and is used with the combo box, later in the same handler (tell menu of popup button “palm_categories”…). This combo box holds all of the names of the categories in Palm, while the all_Cats list holds the same data, along with the category’s correct Palm ID number, which is needed for adding an event to the Palm database.

–On startup, the application looks for the Palm category named Family, and assigns the id number for that category as the current chosen_category_ID, and Family is displayed in the combo box. If that name is not found, it defaults to the first item in the list.

–The choose menu item handler calls the routine for searching the global list (all_Cats) for the ID number of the newly chosen category, which is found in the GetNewPalmCategoryID handler. This handler executes if the user chooses a different Palm category name from the combo box.

You can download Palm Desktop here if you want to play with this, so long as you have access to a non-Intel Mac.

I hope this helps.

I have an application that, on launch, fills in the combo box with the file names in a folder. Maybe you can adapt part of this to add items to your combo box.

on launched theObject
	--Populate Combo Boxes
	set BackTemplatesFolder to PathToBackerTemplates as alias
	list folder BackTemplatesFolder without invisibles
	set CardBackDocList to (result) as list
	tell window "mainWindow"
		tell tab view item "tabCard" of tab view "tabView"
			--Fill Backer Templates drop down with names
			set theseItems to every item in CardBackDocList
			repeat with i from 1 to count theseItems
				tell combo box "backerSelect"
					make new combo box item at end of combo box items with data item i of CardBackDocList
				end tell
			end repeat
		end tell --End tell tab view
	end tell --End tell window
end launched

Model: G5 OSX 10.4.8
Browser: Safari 419.3
Operating System: Mac OS X (10.4)