Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi


how can i clear all textboxes.


i am using this code.
textbox1.text=""
textbox2.text=""
textbox3.text=""
Posted

Use this:

VB
For Each ctrl As Control In Form.Controls            
    If TypeOf ctrl Is TextBox Then
       CType(ctrl, TextBox).Text = String.Empty
    End If
Next ctrl
 
Share this answer
 
Comments
[no name] 16-Sep-11 6:46am    
ok.
but textboxs not clear which is in the group box.
Pradeep Shukla 16-Sep-11 9:31am    
you can make this function a recursive function and it would traverse through all the containers within the form too....
You can try this....
Private Sub clearControl(ByVal ctrls As Control.ControlCollection)

        For Each ctrl As Control In ctrls

            If TypeOf ctrl Is TextBox Then
                CType(ctrl, TextBox).Text = String.Empty
            End If


            If ctrl.Controls.Count > 0 Then

                clearControl(ctrl.Controls)

            End If



        Next
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900