Radiobutton logic ? How to implement auto unchecking others in panel

S

Sagaert Johan

Hi

I am creating a custom control and i want it to behave like a radiobutton :

If multiple radiobuttons are on a panel clicking one unchecks the others.
How is this achieved ?

I want to do the same with my own control when i put multple of them on a
panel or groupbox.

Johan
 
S

Sagaert Johan

Win form

Samuel R. Neff said:
In a web form or win form? Makes a big difference in the answer...

Sam



------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
 
B

Bobbo

I am creating a custom control and i want it to behave like a radiobutton :

If multiple radiobuttons are on a panel clicking one unchecks the others.
How is this achieved ?

Try simply inheriting from RadioButton. I've just tried that now, and
it seems to work fine. If I place two of my new controls on the form,
then only one can be selected at once.
 
S

Samuel R. Neff

That's good, winforms is easier for this question. :)

When you click a winform radiobutton (or set it's checked property to
true) it loops through all sibling controls (i.e., children of it's
parent) and for every radio button it finds that isn't itself it
unchecks it. Pretty straightforward. You can use Reflector to look
at RadioButton.PerformAutoUpdates for exactly what it does.

HTH,

Sam
 

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