フォームのコントロールが空かどうかを確認したいのですが...そのための長いコードがあります。以下にコードを示します。
Public totflag As Boolean
Private Sub BTNSAVE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNSAVE.Click
CheckMyControls()
If totflag = False Then
MessageBox.Show("Give Compleate Data!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
coloring()
ElseIf totflag = True Then
MessageBox.Show("Success", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Public Sub coloring()
Dim txt, cmb, mtxt, rtxt As Control
For Each txt In EMPGBDATA.Controls
If TypeOf txt Is TextBox Then
If txt.Text = "" Then
txt.BackColor = Color.Red
End If
End If
Next
For Each cmb In EMPGBDATA.Controls
If TypeOf cmb Is ComboBox Then
If cmb.Text = "Select" Then
cmb.BackColor = Color.Red
End If
End If
Next
For Each mtxt In EMPGBDATA.Controls
If TypeOf mtxt Is MaskedTextBox Then
If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then
mtxt.BackColor = Color.Red
End If
End If
Next
For Each rtxt In EMPGBDATA.Controls
If TypeOf rtxt Is RichTextBox Then
If rtxt.Text = "" Then
rtxt.BackColor = Color.Red
End If
End If
Next
End Sub
Public Function CheckMyControls() As Boolean
Dim txt, cmb, mtxt, rtxt As Control
Dim flagtxt, flagcmb, flagmtxt, flagrtxt As Boolean
flagtxt = False
For Each txt In EMPGBDATA.Controls
If TypeOf txt Is TextBox Then
If txt.Text = "" Then
flagtxt = True
End If
End If
Next
flagcmb = False
For Each cmb In EMPGBDATA.Controls
If TypeOf cmb Is ComboBox Then
If cmb.Text = "Select" Then
flagcmb = True
End If
End If
Next
flagmtxt = False
For Each mtxt In EMPGBDATA.Controls
If TypeOf mtxt Is MaskedTextBox Then
If mtxt.Text = "" AndAlso mtxt.Name <> "MTXTPFESI" Then
flagmtxt = True
End If
End If
Next
flagrtxt = False
For Each rtxt In EMPGBDATA.Controls
If TypeOf rtxt Is RichTextBox Then
If rtxt.Text = "" Then
flagrtxt = True
End If
End If
Next
If flagtxt = True Or flagcmb = True Or flagmtxt = True Or flagrtxt = True Then
totflag = False
Else
totflag = True
End If
Return totflag
End Function
実際、1つのPFESIテキストボックスをチェックしたくありません。空かどうか。これはマスクされたテキストボックスです。私の問題は、すべてのコントロールにデータがある状態で送信ボタンを押すと、メッセージボックス「GiveCompleteData!」が表示されることです。データのないコントロールにも同じメッセージが表示されます。コードを確認して解決策を教えてください。