Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting the starting index of an NSComboBox



On 23 Jun 2006, at 3:13 PM, Steve Hunt wrote:

I am just starting with Cocoa and I am having a problem in setting the starting index of a NSComboBox control. On startup, the index is not set although the first item is displayed. You have to make a selection to enable the combo box and set an index. In my app, I would like the first item to be selected on startup. I assume the following code:

[calcTypeField selectItemAtIndex:0];

will work, but I cannot determine where to place the code to effect the selection on startup.

You know how to spell "effect;" I like the cut of your jib.

You are no doubt aware of this:
When you set or retrieve a combo box’s value with the standard NSControl methods (such as setStringValue:, stringValue, setFloatValue:, and floatValue), you’re setting or retrieving the value of the combo box’s text field, and not the current selection of the list. Programmatically changing the combo box’s value does not change what’s selected in the combo box’s list. Conversely, programmatically changing what’s selected in the list does not change the text field’s value. If you want the text field value and the list selection to match up, you need to set them individually.
In other words, a combo box is a text field, not a popup menu. When you follow George's advice to initialize in -awakeFromNib, you have to set both item and text if that's what you want.

<http://developer.apple.com/documentation/Cocoa/Conceptual/ComboBox/ Tasks/SettingComboBoxValue.html>

	-- F

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Setting the starting index of an NSComboBox (From: Steve Hunt <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.