Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

I have one requirement to add three check box in a group box, and check-box must react as radio button i.e.,
1. one can check only one check-box at a time.
2. when user goes to check another check box, previous one automatically should be unchecked.
I also know that this is not a good approach to do this, and it's really confusing to non-technical or technical user but I also want to learn something new in this.

I went through lots of sites, but I didn't get any satisfactory solution. I hope I will get good one from you.

With Thanks and Regards,
Ravindra.
Posted
Updated 16-Mar-15 17:41pm
v2
Comments
BillWoodruff 17-Mar-15 1:21am    
What have you tried so far ? Show your code ?

Make a List of Checkboxes and use the same event handler for all of them.
Whenever one is selected store it's index in temp variable, make all checkboxes 'unchecked', then check the one you stored.
 
Share this answer
 
Comments
Ravindra_IND 17-Mar-15 0:14am    
Please send me proper code for this.
First of all, if you know this is not a good solution, you should not do it. The person who gave you this "requirement" could be not competent enough, so you need to convince him/her. This is one of your responsibilities, one of the pretty difficult ones. This is like preventing crime.

It it was a good thing to do, looking for a solution would be a bad idea. Such things should be done from first principles, using original documentation. No wonder you could not find anything — this is way too trivial to write and article on this, or just an answer.

Besides, you did not even indicate what is CheckBox. Which one? Do you think there is only one type with this name? No. This name is ambiguous, so you really need to give us full type name. In all cases, you simply handle the event invoked when a checked state is changed, and change properties in the handler.

—SA
 
Share this answer
 
Comments
Ravindra_IND 17-Mar-15 0:25am    
There are simple three check box to indicate three things for selection respectively and one text box. If one checks anyone things then texbox shows the selected thing.

For example:- Check-box show C#,ASP.NET and MVC respectively.
If one select C# then text-box must show C#.

Thanks...
Sergey Alexandrovich Kryukov 17-Mar-15 0:44am    
Then you should have indicated the full type name: System.Web.UI.WebControls.CheckBox. Please indicate such things in your future questions.
Note that System.Web.UI.WebControls.RadioButton also belong to this type (is derived from CheckBox), and this behavior is already implemented...

...You are welcome. Good luck, call again.

—SA
Ravindra_IND 17-Mar-15 0:48am    
Sir, this is in windows form.
Sergey Alexandrovich Kryukov 17-Mar-15 6:37am    
Very good. There is a previously added tag System.Windows.Forms you can add when edit a question. Please next time use it (or the tags like "WPF", "ASP.NET"), which will make it clear and avoid ambiguity.
—SA
BillWoodruff 17-Mar-15 1:20am    
My vote of #3. This is a lecture full of good advice, and would be appropriate as a comment, but it is not an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900