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
Alte URL:
/snippet/alle-textboxen-zuruecksetzen/507
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]
Danke für die Vereinfachung.
funktioniert leider nicht, wenn die TextBox in einer Panel z.B. liegt.
http://dotnet-snippets.de/dns/Snippet_detail.aspx?=383
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.
Ok, habe deinen Link erst jetzt angeschaut. Und genau das meinte ich auch 😉