|
|
how do i check if a checkbox is checked?
|
|
|
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
i've tried all the variables i can find in the headers... none seem to work... which one is it?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
More. Info.
There is no standard way to tell if a checkbox is checked � the appropriate function varies from framework to framework.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
I'll make some assumptions here, and hope they apply to your situation. If not, then please ignore this post.
Assuming you're using Cocoa and Objective-C, and you're talking about a standard NSButton checkbox...
You can check its state by calling (believe it or not) its "state" method. Check the NSButton documentation for full details. In summary though, an NSButton can be in one of three states: NSOnState, NSOffState, NSMixedState. For a Checkbox, these are represented in the GUI by the tick mark (ie, check mark if you're an American), an empty checkbox, or a hyphen ("-"), respectively.
So in you're code, assuming your checkbox object is called theCheckBox, you can check to see if it's selected this way:
if ( [theCheckBox state] == NSOnState )
or this way:
if ([theCheckBox state] != NSOnState )
etc...
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
ahhhh
I was just saying if([checkbox state]){ .... }
not saying what it was equal to. thanks!
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status:
Offline
|
|
There is also NSOffState as well (which I've used with success).
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Aug 2003
Status:
Offline
|
|
Checkboxes with the mixed state option turned on will also have NSMixedState.
|
-- Devin Lane, Cocoa Programmer
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
How would a check box with a mixed state behave differently?
(
Last edited by poulh; Apr 13, 2005 at 01:15 PM.
)
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
It would display a mixed-state graphic rather than an on or off graphic if its state were set to NSMixedState.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status:
Offline
|
|
oh i see... like a '-' in the box.. good to know.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Sheesh, did you guys even read my post earlier? It does actually mention both NSOffState and NSMixedState, and even the graphic used for each state.
I feel so neglected.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I know. I kind of wondered if people were just joking by repeating the information a little bit at a time.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Aug 2003
Status:
Offline
|
|
Originally Posted by Brass
Sheesh, did you guys even read my post earlier? It does actually mention both NSOffState and NSMixedState, and even the graphic used for each state.
I feel so neglected.
Ack sorry, didn't see that.
|
-- Devin Lane, Cocoa Programmer
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status:
Offline
|
|
Originally Posted by Brass
Sheesh, did you guys even read my post earlier? It does actually mention both NSOffState and NSMixedState, and even the graphic used for each state.
I feel so neglected.
I just looked at your code. There was no mention of NSOffState in your code (you used !=NSOnState).
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally Posted by PBG4 User
I just looked at your code. There was no mention of NSOffState in your code (you used !=NSOnState).
He did, however, mention it in his post.
Originally Posted by Brass
In summary though, an NSButton can be in one of three states: NSOnState, NSOffState, NSMixedState
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally Posted by PBG4 User
I just looked at your code. There was no mention of NSOffState in your code (you used !=NSOnState).
As Chukit said, and as you yourself quoted, I said in "my post", not in "my code". I could have given 6 examples in my code to cover all bases, but I thought that with the 2 examples I posted, and the rest of my post, it was trivially easy to derive the other posibilities.
Gotta leave some thinking up to the reader, eh?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status:
Offline
|
|
Originally Posted by Chuckit
He did, however, mention it in his post.
This is a dev forum. Who looks at the words? I just looked at the code. Guess I'll stop my drive-by postings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|