Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to use check box

like radio button ....
Posted
Updated 28-Jun-19 20:22pm
Comments
Syed Salman Raza Zaidi 23-Jan-12 7:53am    
You mean user should be able to select only one checkbox at a time?

Use radio button as radio button. This way, you could avoid confusing the users.

—SA
 
Share this answer
 
Comments
Maciej Los 8-Jun-12 17:36pm    
Another one good point. +5
Sergey Alexandrovich Kryukov 8-Jun-12 18:01pm    
Thank you, Maciej.
--SA
VJ Reddy 9-Jun-12 1:58am    
Good suggestion. 5!
Sergey Alexandrovich Kryukov 9-Jun-12 22:47pm    
Thank you, VJ.
--SA
Take the CheckedListBox and call ItemCheck Event and use below code It will behave like Radio buttons (It works for me):-
C#
private void chkListBox_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        if (e.NewValue == CheckState.Checked)
        {
            for (int item = 0; item < chkListBox.Items.Count; item++)
            {
                chkListBox.SetItemChecked(item, false);
            }
        }
    }
 
Share this answer
 
v8
If you are referring the design then here is code

if you have two check boxes (Chk1,Chk2) then code like this

on chk1 click event
C#
chk2.Checked=false;


on chk2 click event

C#
chk1.Checked=false;
 
Share this answer
 
Comments
Maciej Los 8-Jun-12 17:38pm    
This is not good practice :(
I'm not down-voting. Correct your answer.
Sergey Alexandrovich Kryukov 9-Jun-12 22:54pm    
You are absolutely right. And RDBurmon, who tried to object you in the comment below is not. Please see my comment.
--SA
RDBurmon 11-Jun-12 1:56am    
You are still talking this non-sense. I said this is not related to UI design.
RDBurmon 9-Jun-12 6:00am    
But OP want to use check box as option button and functionality of option button is It should be selected only one in group right ? That's why I have given this answer and I don't think this is not a good practice.Please re-read the question and then look at the answer losmac . If you feel that you was wrong then please vote the answer with higher vote.
Sergey Alexandrovich Kryukov 9-Jun-12 22:52pm    
This is a wrong approach. Ridiculous question of the type "I want..." should not be answered like that. Explaining how to do wrong thing is making harm instead of helping. You just follow the mistake by OP and try to justify this mistake. The fact you don't see how this is a bad practice is just your problem. You "re-read the question" is not appropriate. We perfectly understood your question; this is you who don't understand important of certain things in UI design.
--SA
For C# Win App
Use CheckedListBox and set Property SelectionMode as One
 
Share this 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