Larry Rungren
asked on
clearing text boxes in multiple panels on a vb2010 form
i have searched around for a method to clear all text boxes on multiple panels and the general consensus seems to me that this will work.
unfortunately it doesn't clear any text boxes at all.
i did see one post that referred to an issue if there is a menustrip, which i do have on the form, but it wasn't clear
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Control
For Each a In Me.GroupBox1.Controls
If TypeOf a Is TextBox Then
a.Text = Nothing
End If
Next
End Sub
unfortunately it doesn't clear any text boxes at all.
i did see one post that referred to an issue if there is a menustrip, which i do have on the form, but it wasn't clear
ASKER
I found a block that does work. republish for any other newbies trying to convert old vb6 code
Public Sub ClearTextBoxes(Optional ByVal ctlcol As Control.ControlCollection = Nothing)
If ctlcol Is Nothing Then ctlcol = Me.Controls
For Each ctl As Control In ctlcol
If TypeOf (ctl) Is TextBox Then
DirectCast(ctl, TextBox).Clear()
Else
If Not ctl.Controls Is Nothing OrElse ctl.Controls.Count <> 0 Then
ClearTextBoxes(ctl.Controls)
End If
End If
Next
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works!
THANKS
THANKS
ASKER