Feedback

Alle Textboxen zurücksetzen

Sprache: VB

Diese Funktion setzt alle Textboxen eines Formulares auf einen Schlag zurück.
Private Sub ClearAllTextboxes()
        For i As Integer = 0 To Me.Controls.Count - 1
            Dim TextboxControl As Control = New Control(CStr(i))
            TextboxControl = Me.Controls(i)
            If TypeOf TextboxControl Is TextBox Then
                TextboxControl.Text = ""
            End If
        Next
End Sub
Private Sub ClearAllTextboxes()
        For i As Integer = 0 To Me.Controls.Count - 1
            Dim TextboxControl As Control = New Control(CStr(i))
            TextboxControl = Me.Controls(i)
            If TypeOf TextboxControl Is TextBox Then
                TextboxControl.Text = ""
            End If
        Next
End Sub

5 Kommentare

  1. Das hätte auch gereicht:
    [code]
    For Each C As Control In Me.Controls
    If TypeOf C Is TextBox Then
    C.Text = „“
    End If
    Next
    [/code]

  2. Wenn man auch in anderen Controls die Textboxen zurücksetzen möchte dann muss man halt auch noch durch diese interieren. In diesem Fall hier rekursiv auf alle controls aufrufen welche nicht eine Textbox sind.