开发者

how to clear all tools in the vb.net from

开发者 https://www.devze.com 2023-02-18 13:42 出处:网络
i have used many of the controls in vb.ne开发者_JAVA百科t forms, including a textbox and combobox, but I want to clear all my text boxes at once, while not typing textbox1.clear() for each one.

i have used many of the controls in vb.ne开发者_JAVA百科t forms, including a textbox and combobox, but I want to clear all my text boxes at once, while not typing textbox1.clear() for each one. Is there any other way to clear all my textboxes?


If I understand you question right, you should be able to loop through all the controls on your form and check to see what Control type they are. Based on their type, either set the textbox Text property to String.Empty, or your ComboBox to the index of a blank ListItem (presumably item zero).

Something like:

For Each ctrl As Control In Me.Controls

    If TypeOf ctrl Is TextBox Then

        CType(ctrl, TextBox).Text = String.Empty

    Else

        ' do something similar for your ComboBox

    End If

Next 


You can parse through each control on your form and test what type of control that is and handle each type separately, but it is easier to simply set each control manually.

Consider writing a ClearForm routine that does all of this, that way all you have to do is call the method.

0

精彩评论

暂无评论...
验证码 换一张
取 消