问题
I am currently making a program in vb.net. it has lots of Text box inside of it. how do i clear them using for each loop.
I have here my code but nothing happens in my program, my text boxes still have data.
For Each txt As TextBox In personalInfo.Controls
txt.Enabled = False
Next
by the way i have three group boxes with text boxes how do i clear all of text boxes with this code.
回答1:
Use
txt.Clear();
for clearing a TextBox. Are you sure that all controls in personalInfo are TextBoxes? If not, use
For Each txt In personalInfo.Controls
If TypeOf (txt) Is TextBox Then
txt.Clear()
End If
Next
来源:https://stackoverflow.com/questions/26195345/loopings-in-vb-net-for-each