|
-
April 1st, 2017, 05:21 PM
#1
Determining which radio button is selected
I have created radio buttons at run time to select a particular file to access. The code is:
Code:
System.Windows.Forms.RadioButton[]
rb = new System.Windows.Forms.RadioButton[fileNamesSaved];
for (int i =0; i < fileNamesSaved; i++)
{
rb[i] = new RadioButton();
rb[i].Text = fileNames[i];
rb[i].Location = new System.Drawing.Point(10, 10+i * 20);
rb[i].Click += new EventHandler(rb_clicked);
this.Controls.Add(rb[i]);
}
test = 0;
}
private void ReturnToBaseForm_Click(object sender, EventArgs e)
{
Form1 f1 = new BaseForm.Form1();
this.Hide();
f1.ShowDialog();
}
private void rb_clicked(object sender, EventArgs e)
{
// need something in here to get the text associated with the particular button that was clicked.
}
The radio buttons are properly created and all use the rb_clicked event handler. What I want to do is to extract the text associated with the button that was clicked. If I look at sender in the debugger the text is there but I don't know how to extract it.
I appreciate any help - have tried a number of possible way to do this but none of them worked
-
April 2nd, 2017, 12:34 AM
#2
Re: Determining which radio button is selected
Put a breakpoint on the closing bracket of the clicked handler. Start debugging and click on a radio button. When the breakpoint hits look at the sender variable and notice its type (it should be a radio button). If it is that type you just need to cast the sender variable into a radio button to access its Text property.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|