ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Clear Mutiple TextBoxes in VB.Net

If you are tired in coding for clearing and specifying the names of multiple TextBoxes on the Form, this tutorial will help you to clear multiple Textboxes without specifying the names of it. It will minimize your code and lessen your work. This method is to clear all the text in the TextBoxes in a certain Form.

 

So, let’s begin:
Open the Visual Basic and create a new Windows Form Application.
After you finish creating a Windows Form Application, drag a Button and the TextBoxes on the Form as much as you can.
clearallform
Double click the Button to fire the click event handler of it. Then, you have to put the code for clearing the Textboxes into it.

  1. 'LOOP THE CONTROL IN THE FORM OF CONTROLS
  2. For Each txt As Control In Me.Controls
  3. 'GETTING THE TYPE OF CONTROL WHICH IS A TEXTBOX
  4. If txt.GetType Is GetType(TextBox) Then
  5. 'CLEARING THE TEXTBOXES
  6. txt.Text = Nothing
  7. End If
  8. Next

Add the pop-up message to notify you that the text has been successfully cleared.

  1. 'IT NOTIFY FIRST BEFORE CLEARING THE TEXT
  2. MsgBox("data cleared")

These are the full codes that you have created.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. 'IT NOTIFY FIRST BEFORE CLEARING THE TEXT
  3. MsgBox("data cleared")
  4.  
  5. 'LOOP THE CONTROL IN THE FORM OF CONTROLS
  6. For Each txt As Control In Me.Controls
  7. 'GETTING THE TYPE OF CONTROL WHICH IS A TEXTBOX
  8. If txt.GetType Is GetType(TextBox) Then
  9. 'CLEARING THE TEXTBOXES
  10. txt.Text = Nothing
  11. End If
  12. Next
  13. End Sub

Now, press F5 on the keyboard to run your project.
You can also download the Complete Source Code  and run it on your computer.

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!