radio Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have a set of forms created with the compact framework each contains a
number of radio buttons in separate groups. I would like to be able to reset
all the buttons at once so if a mistake is made the user can begin again.

i have tried

Dim RadioObj as Radiobutton

For Each RadioObj in me.control then
if RadioObj.checked = True then
 
Heres the rest of that question!!!!!
For Each RadioObj in me.control then
if RadioObj.checked = True then
RadioObj.checked = False
end if
next

this gives me a casting problem and my understanding of this language format
is not good enough for me to figure out whati should change.

Many thenks for your help.
 
In order to share your logic so that it's accessible from multiple forms you
can create a shared method in an isolated class, as shown below.

Public Class SharedLogic
Public Shared Sub ResetAllRadioButtons(ByRef parent As Control)
' If the "parent" does not reference a control then
' return from this subroutine.
If parent Is Nothing Then
Return
End If
' If the "parent" is a RadioButton then ensure that
' it is unchecked.
If TypeOf parent Is RadioButton Then
DirectCast(parent, RadioButton).Checked = False
End If
' Loop through all the children of the "parent" and
' ensure that any RadioButtons that are direct or
' indirect children are unchecked.
For Each ctrl As Control In parent.Controls
ResetAllRadioButtons(ctrl)
Next
End Sub
End Class

Then in order to reset all buttons from the parent "down", in this case all
RadioButtons on the Form, you can use the line of code below from inside the
Forms scope.

' Resets all RadioButtons on the Form.
SharedLogic.ResetAllRadioButtons(Me)

Note that you need to use recursion to clear the RadioButtons in your case
since not all RadioButtons are directly accessible from the Controls
collection of the Form, some of them might be in Panels.
 
Back
Top