I am wanting to be able to check all the controls on a form to see if one or multiple have value. If none have a value, then the end user can close the form without prompt to save. If one or more control types have a value, then prompt to save before closing the form.
I have Comboboxes, MaskedTextBoxes, TextBoxes and ListViews on the same form that I want to check.
I am writing a boolean function right now and want to get your ideas on if I am going about this the right way, or if you think I need to create a boolean for each control type as there are four in total. This is what I have right now.
Code:Public Function CheckIfFormEmpty() As Boolean For Each ctrl As Control In Me.Controls 'Comboox/ListView/MaskedTextBox/TextBox. With ctrl If TypeOf ctrl Is ComboBox Then Select Case .Text.Length Case Is > 0 CheckIfFormEmpty = False Case Else CheckIfFormEmpty = True End Select ElseIf TypeOf ctrl Is ListView Then Dim RowCount As Integer = CType(ctrl, ListView).Items.Count Select Case RowCount Case Is > 0 CheckIfFormEmpty = False Case Else CheckIfFormEmpty = True End Select ElseIf TypeOf ctrl Is TextBox Then Select Case .Text.Length Case Is > 0 CheckIfFormEmpty = False Case Else CheckIfFormEmpty = True End Select ElseIf TypeOf ctrl Is MaskedTextBox Then CType(ctrl, MaskedTextBox).TextMaskFormat = MaskFormat.ExcludePromptAndLiterals Select Case .Text.Length Case Is > 0 CheckIfFormEmpty = False Case Else CheckIfFormEmpty = True End Select End If End With Next ctrl Return CheckIfFormEmpty End Function




Reply With Quote