How to dynamically create and bind radio buttons in Windows form - VB.NET

J

James P.

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 them each in a
GroupBox. All the examples I saw from the books or from the web show
me how to add static radio buttons at design, or dynamically at run
time but with fixed radio buttons (like from an array).

I need to create radio buttons based on the data I have from my SQL
table. This data could be altered by the users. Therefore, if I
create fixed radio buttons, every time the user add a new row or
delete a row, that means I have to go to change it in design or in
code. It's not a practical practice.

Anybody has any examples or any advices? Thank you.
 
C

Chris

You will have to create the buttons and add the to the form at run time. If
you look in the "designer generated code" you will see what VS does to add a
radio button to the form. You just have to do this for each row you want a
radio button created for. Just remember to adjust the size of your group
box for however many radio buttons you add. If I remember correctly (I
haven't checked this) you have to add the radio button the to the controls
object of the group box. but like I said, check out the designer generated
code for an example of adding a radio button to a form/group box

Hope this helps.
Chris
 
P

phamtasmic

Chris said:
You will have to create the buttons and add the to the form at run time. If
you look in the "designer generated code" you will see what VS does to add a
radio button to the form. You just have to do this for each row you want a
radio button created for. Just remember to adjust the size of your group
box for however many radio buttons you add. If I remember correctly (I
haven't checked this) you have to add the radio button the to the controls
object of the group box. but like I said, check out the designer generated
code for an example of adding a radio button to a form/group box

Hope this helps.
Chris

Chris,

Thank you for your suggestion. Are there anyway I can write code to
create those radio buttons based on data in SQL so that it
automatically creates the buttons without me manually write code to
create each and every single button for each row (a description field)
in design or "designer generated code"?

Thank you,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top