01.
Private
Sub
dgvCustomer_DataError(
ByVal
sender
As
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewDataErrorEventArgs)
Handles
dgvCustomer.DataError
02.
Dim
strSubMsg
As
String
=
String
.Empty
03.
04.
If
e.Exception IsNot
Nothing
Then
05.
strSubMsg = e.Exception.Message
06.
End
If
07.
If
strSubMsg.Contains(
"does not allow nulls"
)
OrElse
strSubMsg.Contains(
"to be unique"
)
Then
08.
MessageBox.Show(
"รหัสที่ป้อนมีอยู่แล้วหรือไม่ระบุค่า (null) กรุณาป้อนให้ถูกต้อง"
& Constants.vbCrLf & Constants.vbCrLf & strSubMsg,
"Warning"
, MessageBoxButtons.OK, MessageBoxIcon.
Error
)
09.
ElseIf
strSubMsg.Contains(
"not in a correct format"
)
Then
10.
MessageBox.Show(
"ป้อนข้อมูลไม่ถูกต้อง เช่น จำนวนเงิน แต่ป้อนเป็นตัวอักษร 'หอย' เป็นต้น โอมเพี้ยงป้อนให้ถูกต้อง"
& Constants.vbCrLf & Constants.vbCrLf & strSubMsg,
"Warning"
, MessageBoxButtons.OK, MessageBoxIcon.
Error
)
11.
Else
12.
13.
End
If
14.
Try
15.
e.Cancel =
False
16.
If
dgvCustomer.DataSource IsNot
Nothing
AndAlso
dgvCustomer.DataSource.
GetType
.Name =
"BindingSource"
Then
17.
Dim
ctrSubBindingSource
As
BindingSource = dgvCustomer.DataSource
18.
ctrSubBindingSource.ResumeBinding()
19.
End
If
20.
dgvCustomer.CancelEdit()
21.
Catch
ex
As
Exception
22.
MessageBox.Show(ex.Message,
"Warning"
, MessageBoxButtons.OK)
23.
End
Try
24.
End
Sub