Loopings In VB.NET (FOR EACH)

◇◆丶佛笑我妖孽 提交于 2021-01-29 15:39:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!