Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a generic clearForm function 2

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
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?

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
 
You could try something like:

Code:
    For Each c As Control In frm.Controls
      If c.HasChildren Then
        ClearForm(c)
      Else
        Select Case c.GetType.Name
          Case "TextBox", "RichtextBox"
            c.Text = ""
          Case "DateTimePicker"
            CType(c, DateTimePicker).Value = DateAdd(DateInterval.Day, -1, Now())
          Case "NumericUpDown"
            CType(c, NumericUpDown).Value = 0
          Case "RadioButton"
            CType(c, RadioButton).Checked = False
          Case "CheckBox"
            CType(c, CheckBox).Checked = False
        End Select
      End If
    Next


Hope this helps.

[vampire][bat]
 

I will try this shortly and get back to you. Thank you.

-Ovatvvon :-Q
 
Nice one earthandfire

________________________________________________________
Zameer Abdulla
Help to find Missing people
Even a thief takes ten years to learn his trade.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top