Only allow one checked checkbox in a collection

  • Thread starter Thread starter Bishman
  • Start date Start date
B

Bishman

Hi,

I need to programmatically allow or disallow the selection of multiple
checkboxes on a form . At certain times I only want to allow a single
selection, at other times I may wish to allow multiple. Is there a way of
doing this ?

I dont want to use Radio buttons.....

Thanks,

Jon.
 
Hi,

Bishman said:
Hi,

I need to programmatically allow or disallow the selection of multiple
checkboxes on a form . At certain times I only want to allow a single
selection, at other times I may wish to allow multiple. Is there a way of
doing this ?

I dont want to use Radio buttons.....


Why dont use Radio buttons?
The user expect that a mutually exclusive selection be represented by radio
buttons not checkboxes. If you do not follow this rule your interface will
be weird.


You can do what you want by checking the status of the checkboxes, or the
one that is checked, if another is checked you uncheck the first. You may
found a little issue knowing when (the change of status) was induced by
your code or by the user. but figuring this out is the fun part of the thing
:)
 
Yes, I thought that may be the answer.

Many moons ago when I did a bit of VB4 I thought there was a way of grouping
checkboxs to behave like radio buttons ? Maybe my memory is playing tricks
on me.....

I just wondered if there is the same built in functionailty today ( If there
ever was ! )

Thanks,

Jon.
 
I dont need to inhibit which checkbox they are selecting, I just need to
only allow one.

The problem is inverse if I use Radio buttons as I will only be able to
select a single Button, when on occasion I may need to select multiple.....

JB
 
You need to ask yourself why you are designing a form that uses the same
control for two unrelated purposes. You probably need two different
controls (a radio group, and a check box group) that you enable at different
times according to the application's requirements.

Just my 2c. YMMV.


Peter
 
Hi,

NRao said:
Based on your requirements you need to disable or enable check boxes

No really, because if he disable all other checkboxes there is no way to
select them back.

Basically he needs radiobuttons :)
 
....I think its one of those 'visual' ones !

Thanks for all the responses....
 
Just create client-side or server-side code to check for how many are checked
whenever one is clicked. If the checked count is > 1, make the event sender
unchecked.

Psuedocode:

checkbox_onclick
{
if (Only1Allowed)
if (sender.checked && anyOtherIsChecked())
{
sender.checked = false;
showUserWhy();
}
}
 
You can always set up an event handler that handles all the checkboxes.
Then when someone checks one and sets it to checked, loop through and
uncheck all the other ones.

Robin S.
--------------------------
 
You need to ask yourself why you are designing a form that uses the same
control for two unrelated purposes. You probably need two different
controls (a radio group, and a check box group) that you enable at different
times according to the application's requirements.

I agree with Peter. Put two panels on your Form, one containing
RadioButtons and the other containing CheckBoxes. Show the appropriate
panel at the appropriate time.

This is also nice for the user, who gets a clear, visual cue when they
are allowed to choose multiple choices and when they are allowed to
choose just one.

If you had to do something fancy like allowing up to two choices (but
no more) then I would do it by disabling all of the other check boxes
when the user checks the second one (for immediate feedback) or just
waiting until they push OK to inform them that they chose too many
(the latter being easier and also allows you to establish minimum
numbers of choices).

However, since it's just between "choose one" and "choose as many as
you like", I would go with two sets of controls. A little more work,
but easier for the user to understand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top