Answered by:
RadioButtons

Question
-
I want a pair of radio buttons that tell the datbase that it is a boy or girl and then set properties for both but all that happens when I try it with a message box the message pops up as soon as the form loads and says it is a boy before the radio has been clicked. What am i doing wrong all I can find in the docs is how to get buttons on to a form :-) oh yeah I'm using C# in visual Studio 2008Thursday, November 5, 2009 9:09 AM
Answers
-
Hi,
You shouldn't use groupbox's Enter event. You should use radiobutton's checkedchanged event. Could you please try the code for two radiobuttons in a groupbox?
private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked) { MessageBox.Show("boy"); } } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) { MessageBox.Show("girl"); } }
- Proposed as answer by Noam B Thursday, November 5, 2009 12:12 PM
- Marked as answer by YiChun Chen Friday, November 6, 2009 10:54 AM
Thursday, November 5, 2009 11:55 AM
All replies
-
could you please send your code?Thursday, November 5, 2009 9:24 AM
-
I have deleted it and restarded so many times I have lost count but i'll have another go and see how i get onThursday, November 5, 2009 10:34 AM
-
this is the code but now nothing happens no messages.
private
{
if (radioButton1.Checked)
{
MessageBox.Show("Boy is selected");
}
else if (radioButton2.Checked)
{
MessageBox.Show("Girl is selected");
}
else
{
MessageBox.Show("You have not clicked a raioButton yet");
}Thursday, November 5, 2009 11:36 AM -
Hi,
You shouldn't use groupbox's Enter event. You should use radiobutton's checkedchanged event. Could you please try the code for two radiobuttons in a groupbox?
private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked) { MessageBox.Show("boy"); } } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) { MessageBox.Show("girl"); } }
- Proposed as answer by Noam B Thursday, November 5, 2009 12:12 PM
- Marked as answer by YiChun Chen Friday, November 6, 2009 10:54 AM
Thursday, November 5, 2009 11:55 AM -
still cannot get it to work it is now saying debug is out of date and it throws up 6 errors so I think I'm going to have to reinstall it but will this work with visual 2010 have trid it in both but still cannot work it I think I might go back to Flash lolFriday, November 6, 2009 11:40 AM
-
Hi SharpasDOH,
Thank you for your reply.
Some clarification with you:
What's the 6 errors when you debug your project?
With SYSTEM.IO's code, if we click RadioButton1, the messagebox for "Girl" will appear; if we click RadioButton2, the messagebox for "Boy" will appear.
For further troubleshooting, you can post your code of Form_Load event and Radio Button related code here. I'm willing to help you on that.
Hope this helps! If you have any concern, please feel free to let me know.
Best regards,
Yichun Chen
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Edited by YiChun Chen Monday, November 9, 2009 4:29 AM typo
Monday, November 9, 2009 4:28 AM