JayBeeOH

ClearAllMethod

Feb 6th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.78 KB | None | 0 0
  1. Public Class AddressForm
  2.  
  3.     ' Clear Form's TextBoxes, ComboBoxes, and MaskedTextBoxes
  4.     Private Sub ClearButton_Click(sender As Object, e As EventArgs) _
  5.         Handles ClearButton.Click
  6.  
  7.         ClearAll(Me)
  8.         BillToSameCheckBox.Checked = False
  9.         FirstNameTextBox.Select()
  10.     End Sub
  11.  
  12.     ' Clear TextBoxes, ComboBoxes, and MaskedTextBoxes
  13.     Private Sub ClearAll(ByVal ctrlContainer As Control)
  14.  
  15.         For Each ctrl As Control In ctrlContainer.Controls
  16.             If TypeOf ctrl Is TextBox OrElse
  17.                 TypeOf ctrl Is ComboBox OrElse
  18.                 TypeOf ctrl Is MaskedTextBox Then
  19.                 ctrl.Text = String.Empty
  20.                 If TypeOf ctrl Is ComboBox Then
  21.                     Dim aComboBox = DirectCast(ctrl, ComboBox)
  22.                     aComboBox.SelectedIndex = -1
  23.                 End If
  24.             End If
  25.             ' If the control has children,
  26.             ' recursively call this function
  27.             If ctrl.HasChildren Then
  28.                 ClearAll(ctrl)
  29.             End If
  30.         Next
  31.     End Sub
  32.  
  33.     ' Quick fill Bill To data
  34.     Private Sub BillToSameCheckBoxx_CheckedChanged(sender As Object, e As EventArgs) _
  35.         Handles BillToSameCheckBox.CheckedChanged
  36.  
  37.         If BillToSameCheckBox.Checked Then
  38.             BillToFirstNameNextBox.Text = FirstNameTextBox.Text
  39.             BillToLastNameTextBox.Text = LastNameTextBox.Text
  40.             BillToAddressTextBox.Text = AddressTextBox.Text
  41.             BillToCityTextBox.Text = CityTextBox.Text
  42.             BillToStateComboBox.Text = StateComboBox.Text
  43.             BillToZipCodeMaskedTextBox.Text = ZipCodeMaskedTextBox.Text
  44.         Else
  45.             ClearAll(BillToGroupBox)
  46.             BillToFirstNameNextBox.Select()
  47.         End If
  48.     End Sub
  49. End Class
Advertisement
Add Comment
Please, Sign In to add comment