Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > how do i check if a checkbox is checked?

how do i check if a checkbox is checked?
Thread Tools
poulh
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 11, 2005, 05:33 PM
 
i've tried all the variables i can find in the headers... none seem to work... which one is it?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 11, 2005, 05:34 PM
 
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'."
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 11, 2005, 09:00 PM
 
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...
     
poulh  (op)
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 11, 2005, 10:48 PM
 
ahhhh

I was just saying if([checkbox state]){ .... }


not saying what it was equal to. thanks!
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Apr 12, 2005, 07:49 AM
 
There is also NSOffState as well (which I've used with success).
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
Devin Lane
Forum Regular
Join Date: Aug 2003
Status: Offline
Reply With Quote
Apr 13, 2005, 09:39 AM
 
Checkboxes with the mixed state option turned on will also have NSMixedState.
-- Devin Lane, Cocoa Programmer
     
poulh  (op)
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 13, 2005, 10:57 AM
 
How would a check box with a mixed state behave differently?
( Last edited by poulh; Apr 13, 2005 at 01:15 PM. )
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 13, 2005, 12:48 PM
 
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'."
     
poulh  (op)
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Apr 13, 2005, 01:14 PM
 
oh i see... like a '-' in the box.. good to know.
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 13, 2005, 07:33 PM
 
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.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 13, 2005, 07:42 PM
 
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'."
     
Devin Lane
Forum Regular
Join Date: Aug 2003
Status: Offline
Reply With Quote
Apr 14, 2005, 08:09 PM
 
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
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Apr 15, 2005, 05:09 PM
 
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).
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 15, 2005, 05:56 PM
 
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'."
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Apr 17, 2005, 01:31 AM
 
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?
     
PBG4 User
Senior User
Join Date: Feb 2001
Location: Deer Crossing, CT
Status: Offline
Reply With Quote
Apr 19, 2005, 02:42 PM
 
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.
20" iMac G5! :D AND MacBook 1.83GHz!
Canon Digital Rebel Kit + 75 - 300mm lens. Yum Yum! :D
Check out my OS X Musical Scales program
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:04 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,