473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

radio buttons (array)

Hello,
I need a control which will contain radio buttons that will be added
in a loop.
I am using this control a source of some other control.
I tried to use group box windows control and to add the radio buttons
this way(in a loop):
this.groupBox1.Controls.Add(radio);

but I can see there only one radio button . How can I see all of them
or maybe I should use some kind of radio buttons array first?
Thanks a lot!
Nov 16 '05 #1
6 11158
juli wrote:
but I can see there only one radio button .


Are you sure they're not all stacked on top of each other?

--
There are 10 kinds of people: those who understand binary and those who
don't.
Nov 16 '05 #2
Hi Juli,

The first question is: Where do you want them to appear?

What I'd do is this:

1. Create a user control with three ratio buttons on it, spaced about how
you would like them.
2.. Open up the "#region Designer generated code" region
3.. Take a look at the exact code related to the radio buttons. This
includes a. the initialization of each ratio button. b. the assignment of
properties to the radio button and c. the addition of the ratio buttons to
it's parents controls collection.
4. Write a function with a loop that does the same thing.

Off the top of my head, you might end up with something like this:

private void AddButtons(Control parent, int count)
{
for( int i = 0; i < count; i++ )
{
RadioButton rb = CreateRadioButton(int i,
string.Format("DoWhatever{0}", i) );
parent.Controls.Add(rb);
}
}
private RadioButton CreateRadioButton(int i, string text)
{
RadioButton rb = new RadioButton();
this.rb.BackColor = System.Drawing.Color.White;
this.rb.Checked = (i == 0)? true: false;
this.rb.Location = new System.Drawing.Point(10, 10 + (20 * i));
this.rb.Name = "rb" + i.ToString();
this.rb.Size = new System.Drawing.Size(100, 20);
this.rb.TabIndex = i;
this.rb.TabStop = true;
this.rb.Text = text;
this.rb.CheckedChanged += new
System.EventHandler(this.rb_CheckedChanged);
return rb;
}
private void rb_CheckedChanged(object sender, System.EventArgs e)
{
if( sender.Name == "rb1" ) // Etc.
{
// Do whatever you want to do
}
}
"juli" <ji****@gmail.com> wrote in message
news:1f**************************@posting.google.c om...
Hello,
I need a control which will contain radio buttons that will be added
in a loop.
I am using this control a source of some other control.
I tried to use group box windows control and to add the radio buttons
this way(in a loop):
this.groupBox1.Controls.Add(radio);

but I can see there only one radio button . How can I see all of them
or maybe I should use some kind of radio buttons array first?
Thanks a lot!

Nov 16 '05 #3
Frank is most likely correct. Did you change the .Location property of
each radio button so that it was at different coordinates within the
group box?

Nov 16 '05 #4

Hei,
Thank you all .About the location I did tried to change it but I think I
am not doing it corectly. How exactly I suppose to do it?

I need to add those radio buttons to not a windows control but I need
them to be in a windows control.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5


They probably do but how do I separate them?
Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
myRadioButton.Location = new Point(5, y);
Then increment y for some value (like 20) between each radio button.

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. ...
23
by: Phil Powell | last post by:
<b>Agency 4</b> <input type="radio" name="permission" value="1" checked> Yes <input type="radio" name="permission" value="0" > No <br> <b>Agency 5</b> <input type="radio" name="permission"...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
22
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
7
by: Jerim79 | last post by:
My situation is that I have a form that asks the user for a number. Next, I execute a while loop that displays a group of questions the amount of times the customer entered. For instance, the loop...
5
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.