'http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowvalidating.aspx
Private Sub ValidateByRow(ByVal sender As Object, ByVal data As DataGridViewCellCancelEventArgs) Handles PaymentsDataGridView.RowValidating
Dim row As DataGridViewRow = PaymentsDataGridView.Rows(data.RowIndex)
Dim dateCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("dDate").Index)
Dim descriptionCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("dDescription").Index)
Dim detailsCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("dDetails").Index)
Dim paymentMethodCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("pPaymentMethod").Index)
Dim paymentAmountCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("pPaymentAmount").Index)
Dim GST_catCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("gGST_cat").Index)
Dim GSTAmountCell As DataGridViewCell = row.Cells(PaymentsDataGridView.Columns("gGST_amount").Index)
data.Cancel = Not (IsDateGood(dateCell) AndAlso IsDescriptionGood(descriptionCell) _
AndAlso IsDetailsGood(detailsCell) AndAlso IsPaymentMethodGood(paymentMethodCell) _
AndAlso IsPaymentAmountGood(paymentAmountCell) AndAlso IsGST_catGood(GST_catCell) _
AndAlso IsGSTAmountGood(GSTAmountCell))
End Sub
Private Function IsDescriptionGood(ByRef cell As DataGridViewCell) As Boolean
If cell.Value.ToString().Length = 0 Then
cell.ErrorText = "Please enter a Description"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a Description"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsDetailsGood(ByRef cell As DataGridViewCell) As Boolean
If cell.Value.ToString().Length = 0 Then
cell.ErrorText = "Please enter a Detail"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a Detail"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsPaymentMethodGood(ByRef cell As DataGridViewCell) As Boolean
If cell.Value.ToString().Length = 0 Then
cell.ErrorText = "Please enter a paymentMethod"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a paymentMethod"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsPaymentAmountGood(ByRef cell As DataGridViewCell) As Boolean
If Not Integer.TryParse(cell.Value.ToString(), New Integer()) Then
cell.ErrorText = "Please enter a paymentAmount"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a paymentAmount"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsGST_catGood(ByRef cell As DataGridViewCell) As Boolean
If cell.Value.ToString().Length = 0 Then
cell.ErrorText = "Please enter a GST_cat"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a GST_cat"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsGSTAmountGood(ByRef cell As DataGridViewCell) As Boolean
If Not Integer.TryParse(cell.Value.ToString(), New Integer()) Then
cell.ErrorText = "Please enter a GSTAmount"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Please enter a GSTAmount"
Return False
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function
Private Function IsDateGood(ByRef cell As DataGridViewCell) As Boolean
If cell.Value Is Nothing Then
cell.ErrorText = "Missing date"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Missing date"
Return False
Else
Try
DateTime.Parse(cell.Value.ToString())
Catch ex As FormatException
cell.ErrorText = "Invalid format"
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = "Invalid format"
Return False
End Try
End If
cell.ErrorText = Nothing
PaymentsDataGridView.Rows(cell.RowIndex).ErrorText = Nothing
Return True
End Function