Implementation of RadioButton

B

Baldeep

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
 

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

Top