Christineeve
Programmer
I'm referencing this thread:
This thread and the answers has helped me finally clear all controls in a groupbox on my form.
However, I need help with clearing more than one groupbox on a form. To further complicate the issue:
I have a form with a tab control. Each tab control has multiple group boxes, with mulitple controls including radial/radio buttons, checkboxes, combo boxes and text boxes.
Main Form
-SuperTab Control
--Panels
---GroupBoxes
----Comboboxes, TextBox, Radial Button, etc.
I need to be able to do two things.
One,Clear all fields (which this code does but only one group box not all)
Two, detect if the contents were changed (which I plan on working on after I can clear them all).
I have adapted the owner's code as follows (not very much):
'Calling from the button click
'Code clears all the controls within the groupbox. I have two group boxes and only one cleared.
I'll continue working with this until I can figure out how to sort through each panel and clear them. Your help is appreciated. Thank you.
This thread and the answers has helped me finally clear all controls in a groupbox on my form.
However, I need help with clearing more than one groupbox on a form. To further complicate the issue:
I have a form with a tab control. Each tab control has multiple group boxes, with mulitple controls including radial/radio buttons, checkboxes, combo boxes and text boxes.
Main Form
-SuperTab Control
--Panels
---GroupBoxes
----Comboboxes, TextBox, Radial Button, etc.
I need to be able to do two things.
One,Clear all fields (which this code does but only one group box not all)
Two, detect if the contents were changed (which I plan on working on after I can clear them all).
I have adapted the owner's code as follows (not very much):
'Calling from the button click
Code:
Private Sub cmdCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCheck.Click
'User clicks Clear, so clear all the controls within this panel
Try
clearForm(Panel2)
Catch ex As Exception
End Try
End Sub
'Code clears all the controls within the groupbox. I have two group boxes and only one cleared.
Code:
Private Sub clearForm(ByRef frm As Control)
For Each c As Control In frm.Controls
If c.HasChildren Then
clearForm(c)
Else
Select Case c.GetType.Name
Case "TextBox", "RichtextBox"
c.Text = String.Empty
Case "DateTimePicker"
CType(c, DateTimePicker).Value = DateAdd(DateInterval.Day, -1, Now())
Case "NumericUpDown"
CType(c, NumericUpDown).Value = 0
Case "RadioButton"
CType(c, RadioButton).Checked = False
Case "CheckBox"
CType(c, CheckBox).Checked = False
Case "ComboBox"
CType(c, ComboBox).Text = String.Empty
End Select
End If
Next
End Sub
I'll continue working with this until I can figure out how to sort through each panel and clear them. Your help is appreciated. Thank you.