Hi,
I created several RadioButtons that have a if(RadioButton.Checked == true) part but now
I wanted to create them dynamicly.
So I createt them in like this:
for (int i = 0; i < 6; i++) { radioaddons[i] = new RadioButton(); radioaddons[i].AutoSize = true; radioaddons[i].Name = "radioaddon," + i; radioaddons[i].Size = new System.Drawing.Size(50, 17); radioaddons[i].TabIndex = 10; radioaddons[i].Text = "" + arrayadd[i, 0]; radioaddons[i].UseVisualStyleBackColor = true; groupzustand.Controls.Add(radioaddons[i]); radioaddons[i].Location = new System.Drawing.Point(radioaddons[i-1].Location.X + radioaddons[i-1].Width + 5, 13); radioaddons[i].CheckedChanged += new System.EventHandler(this.radioaddon_CheckedChanged); }
|
The RadioButtons are visible but when I try to find out which button was press with
private void radioaddon_CheckedChanged(object sender, EventArgs e) { int index = 0; for (int i = 0; i < 6; i++) { if (sender.Equals(radioaddons[i])) { index= i; this.Text = "Hello"; } } }
|
The index changed never ever QQ Why??
The sender has the attribut checked true but when I take a look at the right button (lets say at index 5) it says checked = false
I read something about GroupName but in C# there isn't any...
Solution... :
if (((RadioButton)sender).Text == radioaddons[i].Text) { index = i; this.Text = "hello"; }
|
After frustration I simply tried the Text comparison.
Not good but it works. But I really dunno why the Checked and even the Tag attribut didn't work.
So solved!