Code to Clear all TextBox fields in a form

No.of Views1614
Bookmarked0 times
Downloads 
Votes0
By  shanaj   On  16 Feb 2010 03:02:21
Tag : VB.NET , How to
Code to Clear all TextBox fields in a form
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Public Sub ClearTextBoxes(ByVal f As Form)

Dim meuForm As Type = f.GetType()
Dim campos As Reflection.FieldInfo() = meuForm.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)

For Each campo As Reflection.FieldInfo In campos
If campo.FieldType.Name.ToLower = "textbox" Then
Dim t As TextBox = DirectCast(campo.GetValue(f), TextBox)
t.Text = ""
End If
Next

End Sub

Call this function and pass the form name.

NOTE: LIKE  THIS YOU CAN CLEAR ALL CONTROLS USING A SWITCH CASE

 
Sign Up to vote for this article
 
About Author
 
shanaj
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-22 Oct 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top