Hi,

I'm implementing a component that is similar in
functionality to RadioButton. Basically it's a
RadioButton with a different visual representation and it
allows the developer to pick a maximum number of
simultaneously selected buttons. (So instead of just
allowing 1 of n buttons to be checked, you can allow 2 of
n buttons to be checked, etc.)

My question isn't really about how to implement that kind
of control. Rather, I'm curious to know how
RadioButton "know" to uncheck themselves when another
RadioButton in the same group is checked. Does each
RadioButton just go through the Parent.Controls collection
when it is checked? Maybe something like this?

RadioButton rb;
foreach (Control c in this.Parent.Controls)
if (typeof(c) == typeof(this))
{
rb = (RadioButton)(c);
if (rb.Checked)
rb.Checked = false;
}

Seems like there should be a better way to do this..
Would this get slow if the Parent.Controls collection were
large?

Thanks in advance,

Baldeep

Re: Implementation of RadioButton by Joe

Joe
Mon Oct 27 10:40:03 CST 2003

The easiest way to answer this is to actually look at the implementation
code for RadioButton and see what it does. Download Reflector and have
a look.

http://www.aisto.com/roeder/dotnet/


Baldeep wrote:
> Hi,
>
> I'm implementing a component that is similar in
> functionality to RadioButton. Basically it's a
> RadioButton with a different visual representation and it
> allows the developer to pick a maximum number of
> simultaneously selected buttons. (So instead of just
> allowing 1 of n buttons to be checked, you can allow 2 of
> n buttons to be checked, etc.)
>
> My question isn't really about how to implement that kind
> of control. Rather, I'm curious to know how
> RadioButton "know" to uncheck themselves when another
> RadioButton in the same group is checked. Does each
> RadioButton just go through the Parent.Controls collection
> when it is checked? Maybe something like this?
>
> RadioButton rb;
> foreach (Control c in this.Parent.Controls)
> if (typeof(c) == typeof(this))
> {
> rb = (RadioButton)(c);
> if (rb.Checked)
> rb.Checked = false;
> }
>
> Seems like there should be a better way to do this..
> Would this get slow if the Parent.Controls collection were
> large?
>
> Thanks in advance,
>
> Baldeep