I was making a generic function to clear any form before (see thread: thread796-1137573 if curious). Now I wanted to add the ability for the function to also uncheck all radio buttons and checkboxes within the form. I tried adding a reference to the .checked or even .value, but they didn't exist in the list, so I couldn't reference them for the controls on the form. The best thing I could find was .text, but, as you probably know, that only changed the display text for the control, which isn't what I want it to do at all. Here is what I have before, but the checkbox and radio button selections would need altering.
Does anyone know how this could be changed so it will automatically detect radio buttons and checkboxes and clear them from being checked?
-Ovatvvon :-Q
Does anyone know how this could be changed so it will automatically detect radio buttons and checkboxes and clear them from being checked?
Code:
Private Sub clearForm(ByRef frm As Control)
Dim ctl As Control
For Each ctl In frm.Controls
If TypeOf ctl Is GroupBox Then
clearForm(ctl)
Else
If TypeOf ctl Is TextBox Then
ctl.Text = String.Empty
ElseIf TypeOf ctl Is DateTimePicker Then
ctl.Text = DateAdd(DateInterval.Day, -1, Now())
ElseIf TypeOf ctl Is NumericUpDown Then
ctl.Text = 0
ElseIf TypeOf ctl Is RadioButton Then
ctl.Text = 0
ElseIf TypeOf ctl Is CheckBox Then
ctl.Text = 0
End If
End If
Next
End Sub
-Ovatvvon :-Q