C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 26th, 2009, 10:31 AM
Optimum Optimum is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Posts: 570 Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 35 m 39 sec
Reputation Power: 58
Send a message via AIM to Optimum
Check all checkboxes in windows form C#

I have a windows form with something like 20 checkboxes. I have a radio button above that when set one way will check all the boxes and set another way will uncheck them all.

My question is: is there a way to traverse through all the checkboxes on the form and check them in a loop? I don't want to have to manually do it for every checkbox. Thanks

Reply With Quote
  #2  
Old June 26th, 2009, 10:32 AM
Optimum Optimum is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Posts: 570 Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 35 m 39 sec
Reputation Power: 58
Send a message via AIM to Optimum
Get data from new form? C#

I have my main form which launches a new form with a button click. In that new form, a user can select a bunch of options and then hit "continue" button. The button closes that second form and is supposed to give all that data back to the first form. I know it's possible I just don't have a lot of experience with C#. any help? Thanks

Reply With Quote
  #3  
Old June 26th, 2009, 12:31 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
Quote:
Originally Posted by Optimum
I have a windows form with something like 20 checkboxes. I have a radio button above that when set one way will check all the boxes and set another way will uncheck them all.

My question is: is there a way to traverse through all the checkboxes on the form and check them in a loop? I don't want to have to manually do it for every checkbox. Thanks


you can try something along the lines of (not tested)

c# Code:
Original - c# Code
  1.  
  2. foreach(CheckBox chk in form.Controls)
  3. {
  4.    chk.Checked = true;
  5. }









Quote:
I have my main form which launches a new form with a button click. In that new form, a user can select a bunch of options and then hit "continue" button. The button closes that second form and is supposed to give all that data back to the first form. I know it's possible I just don't have a lot of experience with C#. any help? Thanks

you can have a method in the "popup" form call a method in the original form that sets data from your "popup" before you close it.
__________________

Reply With Quote
  #4  
Old June 26th, 2009, 01:37 PM
Optimum Optimum is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Posts: 570 Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 35 m 39 sec
Reputation Power: 58
Send a message via AIM to Optimum
there doesn't seem to be a "Controls" member for the form. The second answer is good tho - thanks

Reply With Quote
  #5  
Old June 26th, 2009, 02:06 PM
Optimum Optimum is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Posts: 570 Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 35 m 39 sec
Reputation Power: 58
Send a message via AIM to Optimum
Actually how can I even access methods from the first form in the second form? I tried passing the form1 object but it doesn't work

Reply With Quote
  #6  
Old June 26th, 2009, 02:28 PM
MadDogBrown MadDogBrown is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Posts: 837 MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 43 m 22 sec
Reputation Power: 526
Quote:
Originally Posted by Optimum
Actually how can I even access methods from the first form in the second form? I tried passing the form1 object but it doesn't work

The methods have to be declared public.

Reply With Quote
  #7  
Old June 26th, 2009, 02:51 PM
nattylife nattylife is offline
Closet coder
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2005
Location: Plantation, FL <---south florida
Posts: 1,431 nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level)nattylife User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 3 Days 13 h 33 m 57 sec
Reputation Power: 152
Send a message via AIM to nattylife
Quote:
Originally Posted by Optimum
there doesn't seem to be a "Controls" member for the form. The second answer is good tho - thanks

are your checkboxes in some container on the form? (like a groupbox or a panel or tabcontrol or such?)

Reply With Quote
  #8  
Old June 26th, 2009, 03:05 PM
Optimum Optimum is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Posts: 570 Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level)Optimum User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 10 h 35 m 39 sec
Reputation Power: 58
Send a message via AIM to Optimum
I know the method must be declared public - but it still doesn't pick up the method.

The checkboxes are in the same groupbox yes.

Reply With Quote
  #9  
Old June 26th, 2009, 03:10 PM
jwdonahue's Avatar
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 3,398 jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level)jwdonahue User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 6 h 48 m 17 sec
Reputation Power: 886
You should not make a form dependent on a parent form's interfaces. This is called a circular dependency and should be avoided. It's bad design because it will make your program brittle and creates major obstacles to code reuse.

The OP's question is more of a .NET/WinForms question than a C# language issue they might find quicker more accurate responses for in the .NET forum.

I'd have to go look it up at MSDN, but I seem to recall there are multiple standard means for passing data between forms. One involves having the parent query the child for it's state before discarding it and the other involves passing some data (usually a pointer/reference) to your constructor that it would save and later use to write back the data.

In any case, you should at least have some intermediary abstraction for the data representing the check-box states. Then, one day if you ever need to reuse that form from some other, all it has to know about are the two data types; the form and the intermediary. There are more than one design pattern available to achieve this. Probably the simplest one would be a wrapper class around your form so all the details of interaction would be completely hidden from the parent.
__________________
My worst nightmare was a pointless infinite loop.
Work in progress; don't poke the curmudgeon!
http://www.odonahue.com/

Reply With Quote
  #10  
Old June 26th, 2009, 10:12 PM
MadDogBrown MadDogBrown is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Posts: 837 MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level)MadDogBrown User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 43 m 22 sec
Reputation Power: 526
Quote:
Originally Posted by jwdonahue
You should not make a form dependent on a parent form's interfaces. This is called a circular dependency and should be avoided. It's bad design because it will make your program brittle and creates major obstacles to code reuse.

Agreed.

But I don't think he is anywhere near ready to process this information.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Check all checkboxes in windows form C#

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap