469,353 Members | 2,050 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

Only allow one checked checkbox in a collection

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.

Feb 20 '07 #1
10 18518

Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
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
:)

Feb 20 '07 #2
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.


"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Oz**************@TK2MSFTNGP02.phx.gbl...
>
Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
>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 :)

Feb 20 '07 #3
Based on your requirements you need to disable or enable check boxes

"Ignacio Machin ( .NET/ C# MVP )" wrote:
>
Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
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
:)

Feb 20 '07 #4
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
"NRao" <NR**@discussions.microsoft.comwrote in message
news:2A**********************************@microsof t.com...
Based on your requirements you need to disable or enable check boxes

"Ignacio Machin ( .NET/ C# MVP )" wrote:
>>
Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
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
:)


Feb 20 '07 #5
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
"Bishman" <jo*************@btinternet.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
>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
"NRao" <NR**@discussions.microsoft.comwrote in message
news:2A**********************************@microsof t.com...
>Based on your requirements you need to disable or enable check boxes

"Ignacio Machin ( .NET/ C# MVP )" wrote:
>>>
Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
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
:)



Feb 20 '07 #6
Hi,

"NRao" <NR**@discussions.microsoft.comwrote in message
news:2A**********************************@microsof t.com...
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 :)
Feb 20 '07 #7
....I think its one of those 'visual' ones !

Thanks for all the responses....
"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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
"Bishman" <jo*************@btinternet.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
>>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
"NRao" <NR**@discussions.microsoft.comwrote in message
news:2A**********************************@microso ft.com...
>>Based on your requirements you need to disable or enable check boxes

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl...
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
:)




Feb 20 '07 #8
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();
}
}
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Bishman" wrote:
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.

Feb 20 '07 #9
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.
--------------------------
"Bishman" <jo*************@btinternet.comwrote in message
news:eu**************@TK2MSFTNGP02.phx.gbl...
...I think its one of those 'visual' ones !

Thanks for all the responses....
"Peter Bradley" <pb******@uwic.ac.ukwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>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
"Bishman" <jo*************@btinternet.comwrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
>>>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
"NRao" <NR**@discussions.microsoft.comwrote in message
news:2A**********************************@micros oft.com...
Based on your requirements you need to disable or enable check boxes

"Ignacio Machin ( .NET/ C# MVP )" wrote:

>
Hi,
>
"Bishman" <jo*************@btinternet.comwrote in message
news:O8**************@TK2MSFTNGP02.phx.gbl.. .
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
:)
>
>
>
>




Feb 21 '07 #10
On Feb 20, 8:16 am, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
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.

Feb 21 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Joel Brabant | last post: by
2 posts views Thread by /.. | last post: by
2 posts views Thread by Wayne Wengert | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.