Question Radio button selection from groupbox

shruts

Member
Joined
Sep 13, 2011
Messages
7
Programming Experience
1-3
Dear All,

I have a group of radio buttons inside a Groupbox and would like to get a feedback as to which radio button is selected when the user clicks on any one of them.

Regards
 
I think you mean 'checked' and not 'selected', selecting is not relevant for the RadioButton control, it only reflects the Checked state.
First use the designer: select all the RadioButton controls, use the Properties windows and select Events and find the CheckedChanged event, write a name for the event handler and press Enter (or alternative just doubleclick the CheckedChanged event and IDE will make up a name).
You are now brought to the code for the event handler. You can see the event handler has two parameters (sender As Object, e As EventArgs). The sender parameter identifies the control instance that raised the event. Since it is type Object you have to cast (CType/DirectCast) to the type you need to use, in this case type RadioButton.
As the name of the event implies, CheckedChanged notifies when the Checked property of the control changes. This happens both when the control is checked and unchecked, so in your code you can test if the current 'sender' control is checked or not.
Finally when you have handled the event and found if control has just been checked you can give the kind of feedback you need as to which control raised the event, using probably the controls Name property or the Text property.
 
Back
Top