Click here to Skip to main content
15,914,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know this should be simple but I can't seem to find the answer anywhere.

In VB6 I seem to recall being able to create an array of Radio Buttons (in fact I think it had to be) so that testing when was as simple as scanning across the array.

I don't want to use a group box because that doesn't fit visually with my design ... so how can I create a simple grouping of Radio buttons on my panel that I can scan when the user hits the save button I've created to determine what option they want (and that they've selected at least one option).

Thanks.
Posted

You can create a Panel with no border, and put the radio buttons into that. At that point you can just enumerate the child controls. Personally, I simply maintain a single variable that indicates the currently selected radio button in a given group.
 
Share this answer
 
Comments
BHort 14-Sep-11 10:58am    
Is it possible to create (in the designer) an array of radio buttons?
#realJSOP 14-Sep-11 11:32am    
Sure it is, but creating a panel does that for you as you add child controls to it. Why go through the hassle of creating your own?
I actually found an article on another site that describes the way to make this work.

You create 1 event handler and then change the Handles portion to list all of the radio buttons you want handled.

This way you only need a single event handler whenever any of the radio buttons is checked and you can update a variable to show which one is currently selected.

Putting code into the forms constructor will allow you to map the individual radio buttons to an array of radio buttons allowing you to iterate over the buttons using the array.

Not quite as trivial as it was in VB6 but it can still be done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900