Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai

I have taken 9 radio buttons in a group box.If we check one radio button that button text

will be displayed into textbox. For that we have to write code in the checkedchanged

event for every radio button. I don't want to write code for all buttons can i write any one line code for that.

Please suggest me
Posted
Comments
Kornfeld Eliyahu Peter 26-Nov-14 4:36am    
Event handler is no more than a method attached to some event. Simple attach the same method to all buttons...

Yes, go to Properties, then Events and set the same Event for every Radio Button.
 
Share this answer
 
Comments
/\jmot 26-Nov-14 5:15am    
Easy process.
+5
Thanks. :)
another way...

C#
radioButton1.CheckedChanged += new EventHandler(radioButtons_CheckedChanged);
radioButton2.CheckedChanged += new EventHandler(radioButtons_CheckedChanged);
.
.
.
.

private void radioButtons_CheckedChanged (object sender, EventArgs e)
{
    RadioButton radioButton = sender as RadioButton;

    if (radioButton1.Checked)
    {
        // Do stuff 
    }
    else if (radioButton2.Checked)
    {
        // Do other stuff
    }
}


select all radio button inside a group box..
C#
var Radio = new []{groupBoxId}.SelectMany(g=>g.Controls.OfType<RadioButton>());
 
Share this answer
 
v2
Comments
Take my 5 as well. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900