How do I easily clear textboxes on a form

Posted on 2006-03-23
Last Modified: 2010-04-23
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?
Question by:vlvawter
    LVL 85

    Accepted Solution

    One way...

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        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
                End If
        End Sub

    Author Comment


    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.

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    It's possible via Reflection but I think that should be another question.

    You can reduce the points on this one if you want.  =)

    Author Comment


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now