Clearing Textboxes on form GroupBox

Posted on 2004-11-25
Last Modified: 2010-04-23

I have 10 texboxes placed in  a groupBox on a windowsform. I would like to clearall the texboxes  .
Is there a way to specify which textboxes in the 10 present  I dont want to clear looping thru the textboxes on the form
like if txtname then avoid clearing it
Thx in advance
Question by:sainavya1215
    LVL 14

    Expert Comment

    You can put the textboxes into an array & then check the names to determine if you want to clear them or not:

    Dim atxtboxes as TextBox() = {Textbox1, Textbox2, Textbox3, TextBox4, TextBox5, TextBox6, Textbox7, Textbox8, Textbox9, Textbox10}

    Dim ii As Integer
    For ii = 0 to atxtboxes.Length-1
         Select Case atxtboxes(ii).Name
              Case "TextBox1", "TextBox3"       'Clear all textboxes in array EXCEPT Textbox1 & Textbox3
              Case Else
                   atxtboxes(ii).Text = String.Empty
          End Select

    Author Comment

    Dim atxtboxes as TextBox() = {Textbox1, Textbox2, Textbox3, TextBox4, TextBox5, TextBox6, Textbox7, Textbox8, Textbox9, Textbox10}

    Is this an array..... ?? Instead of mentioning all the textboxes in array cant we do it by looping thru textbox controls on form

    Author Comment

    MoreOver these textboxes as mentioned are placed in Groupbox
    LVL 14

    Accepted Solution

    Sure you can. Here's what that code would look like:

    For Each ctl As Control In GroupBox1.Controls
        If TypeOf(ctl) Is TextBox Then
            ctl.Text = String.Empty
        End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    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 (…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    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…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now