• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

How do I easily clear textboxes on a form

I have textboxes, comboboxes on a form with the boxes separated within groupboxes.  I need to clear the text properties of these periodically.  Is there a simple way to do this?
0
vlvawter
Asked:
vlvawter
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
One way...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ClearFields(Me)
    End Sub

    Private Sub ClearFields(ByVal container As Control)
        For Each ctl As Control In container.Controls
            If TypeOf ctl Is TextBox OrElse TypeOf ctl Is ComboBox Then
                ctl.Text = ""
            ElseIf ctl.Controls.Count > 0 Then
                ClearFields(ctl)
            End If
        Next
    End Sub
0
 
vlvawterAuthor Commented:
Idle,

Thanks, the code worked fine.  I have an add on question for another 100 points if you're interested.

Is there a simple way to set all the public properties of  an object to Nothing (or the string values to "" and integers to 0)?

If you're not interest, please post and I'll award your points and set my public properties up as a separate question.

Thanks.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It's possible via Reflection but I think that should be another question.

You can reduce the points on this one if you want.  =)
0
 
vlvawterAuthor Commented:
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now