Radio Buttons
Hi,
I have this problem:
In my application i have a dataset with some rows, and for each row i design some labels and a textbox and 2 radio buttons dinamically, so my problem is that for example if i have 4 lines (8 radio buttons) i only can have 1 radio button selected. I want to have 1 radio button selected by line, does anyone know how can i do this?
Thanks.
Hi,
By design, all radio-buttons in the same control are part of the same "group" (i.e. only one can be select). To select one per line, you'll need to have a separate Panel per grouping of radio-buttons, and add the radio-buttons to the Panel.
--Jeff
Thanks, but this only works for statics screens.
I have this:
/////////////////////////////////////////////////////////////
aRbtAnswerYes[x] =
new RadioButton();aRbtAnswerYes[x].Size =
new Size(60, 30);aRbtAnswerYes[x].Text =
"S";aRbtAnswerYes[x].Checked =
true;//aRbtAnswerYes[x].BringToFront();//aRbtAnswerYes[x].Name = x.ToString();//this.aPanelAnswer[x].Controls.Add(this.aRbtAnswerYes[x]);//this.Controls.Add(this.aRbtAnswerYes[x]);aRbtAnswerYes[x].Location =
new System.Drawing.Point(394, y);//////////////////////////////////////////////////////////////////aRbtAnswerNo[x] = new RadioButton();
aRbtAnswerNo[x].Size =
new Size(60, 30);//aRbtAnswerNo[x].Font = new Font("Tahoma", 6, System.Drawing.FontStyle.Regular);//aRbtAnswerNo[x]. Name = x.ToString();aRbtAnswerNo[x].Text =
"N";//aRbtAnswerNo[x].BringToFront();//this.aPanelAnswer[x].Controls.Add(this.aRbtAnswerNo[x]);//this.Controls.Add(this.aRbtAnswerNo[x]);aRbtAnswerNo[x].Location =
new System.Drawing.Point(394, y+40);//PanelaPanelAnswer[x] =
new Panel();aPanelAnswer[x].Size =
new System.Drawing.Size(67, 90);aPanelAnswer[x].BackColor = System.Drawing.
Color.Red; this.aPanelAnswer[x].Controls.Add(aRbtAnswerYes[x]);this.aPanelAnswer[x].Controls.Add(aRbtAnswerNo[x]);this.Controls.Add(aPanelAnswer[x]);aPanelAnswer[x].Location =
new System.Drawing.Point(394, y);this.aPanelAnswer[x].ResumeLayout(false);
With this panels appears but radiobuttons don't, anybody knows what's wrong?
Thanks.
You're setting the location of the 2 radio-buttons to something like (394, y). However, because the radio-buttons are children of the Panel control, that location is relative to their parent Panel control... thus they're probably not appearing because they're way off the edge of the screen. You can verify that by, in the properties window, selecting one of the radio-buttons from the drop-down list at the top (it will probably appear way off to the right somewhere). You'll want to set their location to something like (0,0) and (0,40). Because you will have a separate panel for each set of radio-buttons, you don't need to use 'y' at all in the locations... each radio button will be in the same place relative to its parent panel.
Also, a couple other things I noticed... you have System.Drawing.Size() specified in some places, but only Size() in others. I assume that you have a "using System.Drawing" somewhere so that is getting resolved correctly, but just wanted to make sure. And you don't have an "aPanelAnswer[x].SuspendLayout()" in the code you posted. Since aPanelAnswer[x] was created right there, I assume that's actually missing, and you should probably add that.
Hope that helps,
--Jeff
Thanks for your feedback.
I already solved the problem with checkboxs (with the same behaviour of radiobuttons).
Note: My application is running on a PDA with a resolution of 640x480.