Answered by:
clear all textboxes

Question
-
Hi all
Im trying to easily clear the contents of all textboxes on my form, think im almsot there but now quite, can anyone assist please
Code SnippetSub
Clear() Dim txt As TextBox For Each txt In Form1.Textboxstxt.Clear()
Next End Subthanks
gibbo
Saturday, May 19, 2007 12:08 PM
Answers
-
Dim ctrl As Control
Dim txt As TextBox
For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
txt = CType(ctrl, TextBox)
txt.Text = ""
End If
Nexttry this...hope u get this..
Saturday, May 19, 2007 12:12 PM -
for C#
this may work
foreach(Control control in this.Controls)
{
if(control.GetType() == typeof(TextBox))
{
control.Text = "";
}
}
Saturday, May 19, 2007 12:16 PM -
Simpler code for VB:
For Each ctl As Control In Controls
If TypeOf ctl Is TextBox Then
CType(ctl, TextBox).Clear()
End If
Next ctlSaturday, May 19, 2007 8:20 PM
All replies
-
Dim ctrl As Control
Dim txt As TextBox
For Each ctrl In Me.Controls
If (ctrl.GetType() Is GetType(TextBox)) Then
txt = CType(ctrl, TextBox)
txt.Text = ""
End If
Nexttry this...hope u get this..
Saturday, May 19, 2007 12:12 PM -
for C#
this may work
foreach(Control control in this.Controls)
{
if(control.GetType() == typeof(TextBox))
{
control.Text = "";
}
}
Saturday, May 19, 2007 12:16 PM -
Simpler code for VB:
For Each ctl As Control In Controls
If TypeOf ctl Is TextBox Then
CType(ctl, TextBox).Clear()
End If
Next ctlSaturday, May 19, 2007 8:20 PM -
thanks guys
gibbo
Saturday, May 19, 2007 9:24 PM -
oh man..welcome..but u can mark more than one ans as answers..no prob ..mine was right perfctly too ..
Wednesday, May 23, 2007 5:53 AM