VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursi

by Taklikar AH (3 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 28th September 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursive call to the function so as to go thru

API Declarations


Dim arrControl() As Control.ControlCollection



'Loop counter
Dim t As Integer = 0



'Array counter
Dim arrCounter As Integer = 0


Rate Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursi



        'Call a function to fill the data of all
        'text boxes with ""
        Call FillData(Me.Controls)
    End Sub

 

    Function FillData(ByVal p As Object)
        Dim ctrl As New Control()
        Dim j As Integer

 

        'Loop thru all the controls of p 
        For Each ctrl In p
            If ctrl.Controls.Count > 0 Then
                'Redim the array
                ReDim Preserve arrControl(t)
                arrControl(t) = ctrl.Controls
                t += 1
            Else
                'Check if textbox
                If TypeOf (ctrl) Is TextBox Then
                    ctrl.Text = ""
                End If
            End If

 

        Next

 

        For j = arrCounter To t - 1
            arrCounter += 1
            'Call recursive function to fetch all the
            'containers (inside container too)
            FillData(arrControl(j))
            Exit Function
        Next j
    End Function


Download this snippet    Add to My Saved Code

Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursi Comments

No comments have been posted about Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursi. Why not be the first to post a comment about Loop thru all the controls in a VB.NET form and make all the textboxes empty. The code uses recursi.

Post your comment

Subject:
Message:
0/1000 characters