K Feening
asked on
VB Clearing Controls
Hi
I create Controls in a Tabpage called extraTabPage
dim txt as new system.windows.forms.TextB ox
dim pkr as new system.windows.forms.DateT imePicker
dim btn as new system.windows.forms.Butto n
extratabpage.Control.Add(t xt)
extratabpage.Control.Add(p kr)
I add about 3 or 4 of each setting height and position as I go
Then create a button
extratabpage.Control.Add(b tn)
btn.text = "Clear Entries"
add Handler btn.click, address of ClearEntries
End sub
Private Sub ClearEntries(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
Dim ctrl As Control
For Each ctrl In mExtraTabPage.Controls
If (ctrl.GetType() IsNot CType(ctrl, Button)) Then
If (ctrl.GetType() Is CType(ctrl, TextBox)) Then
Dim txt As TextBox = CType(ctrl, TextBox)
txt.Text = ""
End If
If (ctrl.GetType() Is CType(ctrl, DateTimePicker)) Then
Dim Cal As DateTimePicker = CType(ctrl, DateTimePicker)
Cal.Format = DateTimePickerFormat.Custo m
Cal.CustomFormat = " "
End If
End If
Next
End Sub
when the clearentries is called I get an error
Unable to cast object of type system.windows.forms.butto n to type system.windows.forms.TextB ox
Thanks
I create Controls in a Tabpage called extraTabPage
dim txt as new system.windows.forms.TextB
dim pkr as new system.windows.forms.DateT
dim btn as new system.windows.forms.Butto
extratabpage.Control.Add(t
extratabpage.Control.Add(p
I add about 3 or 4 of each setting height and position as I go
Then create a button
extratabpage.Control.Add(b
btn.text = "Clear Entries"
add Handler btn.click, address of ClearEntries
End sub
Private Sub ClearEntries(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
Dim ctrl As Control
For Each ctrl In mExtraTabPage.Controls
If (ctrl.GetType() IsNot CType(ctrl, Button)) Then
If (ctrl.GetType() Is CType(ctrl, TextBox)) Then
Dim txt As TextBox = CType(ctrl, TextBox)
txt.Text = ""
End If
If (ctrl.GetType() Is CType(ctrl, DateTimePicker)) Then
Dim Cal As DateTimePicker = CType(ctrl, DateTimePicker)
Cal.Format = DateTimePickerFormat.Custo
Cal.CustomFormat = " "
End If
End If
Next
End Sub
when the clearentries is called I get an error
Unable to cast object of type system.windows.forms.butto
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
had to use in body of code as well as
if typeof(ctrl) is textbox then to clear the text box