Clean massive checks on VB.NET

0

I have the following code to clean the controls of a form, these were grouped by GroupBox and before it worked perfectly, now I had to add a panel to control my form better and this code already Do not you do the task I require, any suggestions?

Public Sub limpiarControles()
    Dim ctrl As Control
    Dim ctrlHijo As Control

    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Then
            ctrl.Text = ""               
        ElseIf ctrl.HasChildren Then     
            For Each ctrlHijo In ctrl.Controls
                If TypeOf ctrlHijo Is TextBox Then
                     ctrlHijo.Text = ""                        
                End If
            Next
        End If
    Next
    
asked by SdeSistemas 06.11.2018 в 22:00
source

1 answer

0

Try this to do a review so that it does not fail until you leave no text ...

Public Function existenControles() As Boolean
    existenControles = false
    On Error Resume Next
    Dim ctrl As Control
    Dim ctrlHijo As Control

    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Then
           existenControles = true 
           Exit Function                
        Else
            If ctrl.HasChildren Then     
             For Each ctrlHijo In ctrl.Controls
                If TypeOf ctrlHijo Is TextBox Then
                     existenControles = true 
                     Exit Function
                End If
             Next
            End If
        End If
    Next
End Function



Public Sub limpiarControles()
  On Error Resume Next
  Dim ctrl As Control
  Dim ctrlHijo As Control

  Do Until (existenControles = True)
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Then
            ctrl.Text = ""               
        Else
            If ctrl.HasChildren Then     
             For Each ctrlHijo In ctrl.Controls
                If TypeOf ctrlHijo Is TextBox Then
                     ctrlHijo.Text = ""                        
                End If
             Next
            End If
        End If
    Next
  Loop
End Sub
    
answered by 12.11.2018 в 23:20