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?
This is my code that I personally use it in my projects ^_^
ClearAll TextBoxes : For Each TxtBox In Me.Controls.OfType(Of TextBox) TxtBox.Clear() Next TxtBox
You could put them in an array then loop through the array:
You can iterate over all controls on the form which are contained in
root.Controls
and see if it is of type a textboxTypeOf ctrl Is TextBox
, then you can clear the text in that controlCType(ctrl, TextBox).Text = String.Empty
Well!! You need to use recursion to loop through all controls
Adding the code:
I tried one of the examples here but this seems to work for me:
try this one
or
if .Clear() is a member of textbox property then use it. i guess .clear() is not a member of textbox properties.
I had to cast the Control as a TextBox to make this work. Something about the control object not being accessible. There may be a more direct way but I was unable to find one.
I got the idea from https://stackoverflow.com/a/16264904/11242863
I hope this helps someone,
Tim R