I am using the following code to clear the
txtint1.Clear()
txtext1.Clear()
txttot1.Clear()
txtint2.Clear()
txtext2.Clear()
txttot2.Clear()
txtint3.Clear()
txtext3.Clear()
txttot3.Clear()
txtint4.Clear()
txtext4.Clear()
txttot4.Clear()
txtint5.Clear()
txtext5.Clear()
txttot5.Clear()
txtint6.Clear()
txtext6.Clear()
txttot7.Clear()
txtint8.Clear()
txtext8.Clear()
txttot8.Clear()
Is there any possibility to clear all the textbox controls at once or with few lines of code?
Use Clear to explicitly clear the Err object after an error has been handled, for example, when you use deferred error handling with On Error Resume Next. The Clear method is called automatically whenever any of the following statements is executed: Any type of Resume statement. Exit Sub, Exit Function, Exit Property.
Typically, a TextBox control is used to display, or accept as input, a single line of text. You can use the Multiline and ScrollBars properties to enable multiple lines of text to be displayed or entered.
You can iterate over all controls on the form which are contained in root.Controls
and see if it is of type a textbox TypeOf ctrl Is TextBox
, then you can clear the text in that control CType(ctrl, TextBox).Text = String.Empty
Well!! You need to use recursion to loop through all controls
Adding the code:
Public Sub ClearTextBox(parent As Control)
For Each child As Control In parent.Controls
ClearTextBox(child)
Next
If TryCast(parent, TextBox) IsNot Nothing Then
TryCast(parent, TextBox).Text = [String].Empty
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With