Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub dgChecks_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgChecks.CellValidating
Dim ValDate As Date = Nothing
Dim ValLong As Long = 0
Dim valDec As Decimal = 0.0
Me.Cursor = Cursors.WaitCursor
Try
If dgChecks.Item(e.ColumnIndex, e.RowIndex).IsInEditMode = True Then
Select Case dgChecks.Columns(e.ColumnIndex).Name
Case "CheckNum"
If e.FormattedValue <> "" Then
If Long.TryParse(e.FormattedValue, ValLong) = False Then
e.Cancel = True
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = "Invalid Check Number (" & _
dgChecks.Item(e.ColumnIndex, e.RowIndex).Value & "). Must be a numeric value to continue."
Else
e.Cancel = False
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = String.Empty
End If
End If
Case "DateCleared" ', "IssueDate"
If e.FormattedValue <> "" Then
If Date.TryParse(e.FormattedValue, ValDate) = True Then
If ValDate.Ticks < 1 Then
e.Cancel = True
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = "Invalid Date(" & _
dgChecks.Item(e.ColumnIndex, e.RowIndex).Value & "). Must be a valid date using the format 'mm/dd/yyyy'."
Else
e.Cancel = False
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = String.Empty
End If
Else
e.Cancel = True
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = "Invalid Date(" & _
dgChecks.Item(e.ColumnIndex, e.RowIndex).Value & "). Must be a valid date using the format 'mm/dd/yyyy'."
End If
End If
Case "Amount"
If e.FormattedValue <> "" Then
If Decimal.TryParse(e.FormattedValue, valDec) = False Then
e.Cancel = True
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = "Invalid Check Amount (" & _
dgChecks.Item(e.ColumnIndex, e.RowIndex).Value & "). Must be a numeric value to continue."
Else
e.Cancel = False
dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText = String.Empty
End If
End If
End Select
'End If
End If
txtMsg.Text = dgChecks.Item(e.ColumnIndex, e.RowIndex).ErrorText
[COLOR=green]'Put your database update statement here if e.cancel = false.[/color]
Catch ex As Exception
ex.Source = System.Reflection.MethodBase.GetCurrentMethod.Name
ErrorLog(Err.Number, Err.Description, Me.Name, ex.Source, Err.Erl)
txtMsg.Text = "Error: " & ex.Message
End Try
Me.Cursor = Cursors.Default
End Sub
Private dList As DataSet
Public Function GridSets(ByVal DtGrid As DataGridView) As Boolean
If Cnn Is Nothing Then Cnn = New SqlClient.SqlConnection(CnnStr)
If Cnn.State <> ConnectionState.Open Then Cnn.Open()
If Cmd Is Nothing Then Cmd = New SqlClient.SqlCommand(CmdStr)
If Rst Is Nothing Then Rst = New SqlClient.SqlDataAdapter(Cmd)
If dList Is Nothing Then dList = New DataSet
Try
Rst.SelectCommand.Connection = Cnn
Rst.SelectCommand = Cmd
Rst.SelectCommand.CommandType = CmdType
Rst.SelectCommand.CommandText = CmdStr
Rst.Fill(dList)
DtGrid.DataSource = dList.Tables(0)
GridSets = True
Catch ex As Exception
Errs.Description = ex.Message
Errs.Number = Err.Number
Errs.Source = Err.Source & ".GridSets"
Errs.Line = Err.Erl
GridSets = False
End Try
End Function