Thanks for the posts - I actually had looked at that validation tutorial - I had not yet put the CellEndEdit into my code because the comments on it said "for when the user press esc"; but I was only tabing thru the fields; I hadn't realized it got rid of the icon I just thought it cleared the error text. - So that issue has been taken care of.
----------------------------------
But as for the line being deleted after entry - I know it still has to do with the validation on the columns of the field in the datafile that I have not included in datagrid. I have tried tracing the code thru and still can't completely understand how to avoid this. I have found a post where someone has used e.ThrowException = False
to stop the errors and I've tried using it a couple different ways with no success. I am used to always putting userids and timestamps on transactions when working on mainframe systems. So I would think when systems are being developed in vb analysts would want that included as well and would be fairly common (with all happening behind the scenes for the user). Which I would have thought I would come across some examples of how that would work together - I have tried to get an ADO.net book to help me understand but by my project/contract is over before the book would arrive.
------------
I would appreciate it if you could look at my code and help with this. My brain is running on fumes.
-------
My datafile is SwipeId(autonum),EmpNum,PPday,InputType,SupReasonCode,PayCode,Amount,Comments,UserId and Timestamp,
----
My Grid has PPDay,PayCode,SupReasonCode,Amount and Comments - The user does need to enter the rest because Empnum I want to fill with what the selected from the combobox so they don't have to enter everytime. Autonum,Input type Userid and Timestamp are generated.
-----------------------------------
Here is some of my code
Private Sub SwipeAccumulativeHoursDataGridView_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles SwipeAccumulativeHoursDataGridView.CellValidating
'Validate the Payperiod entry by disallowing empty strings.
If SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).IsNewRow Then Return
If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).Name = "PPDay" Then
If e.FormattedValue IsNot Nothing AndAlso _
String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = _
"You Must enter a Date"
e.Cancel = True
End If
If e.FormattedValue < StartDate Or e.FormattedValue > EndDate Then
SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = _
"Date entered is not within payperiod"
e.Cancel = True
End If
End If
If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).Name = "PayCode" Then
If e.FormattedValue IsNot Nothing AndAlso _
String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = _
"You must Enter a paycode"
e.Cancel = True
End If
End If
'If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).Name = "SupReason" Then
' If e.FormattedValue IsNot Nothing AndAlso _
' String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
' SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = _
' "SupReason"
' e.Cancel = True
' End If
' End If
If SwipeAccumulativeHoursDataGridView.Columns(e.ColumnIndex).Name = "Amount" Then
If e.FormattedValue IsNot Nothing AndAlso _
String.IsNullOrEmpty(e.FormattedValue.ToString()) Then
SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = _
"You must enter an Amount"
e.Cancel = True
End If
End If
End Sub
--------------------------
Private Sub SwipeAccumulativeHoursDataGridView_CellEndEdit(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles SwipeAccumulativeHoursDataGridView.CellEndEdit
' Clear the row error in case the user presses ESC.
SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).ErrorText = String.Empty
End Sub
------------------------
Private Sub SwipeAccumulativeHoursDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles SwipeAccumulativeHoursDataGridView.DataError
Debug.WriteLine(SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
e.ThrowException = False
Select Case e.ColumnIndex
Case 0
MessageBox.Show("Invalid Date" _
& e.Context.ToString())
Case 1
MessageBox.Show("Error happened in data error case 1" _
& e.Context.ToString())
Case 2
If (SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).IsNewRow) Then
e.ThrowException = False
End If
'If IsDBNull((SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)) Then
' Debug.WriteLine(SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
' MessageBox.Show("Error happened in data error case 2 isdbnull" _
' & e.Context.ToString())
'Else
' If ((SwipeAccumulativeHoursDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)) = Space() Then
' MessageBox.Show("Error happened in data error case 2 not isdbnull is spaces" _
' & e.Context.ToString())
' Else
' MessageBox.Show("Error happened in data error case 2 not isdbnull is not spaces" _
' & e.Context.ToString())
' End If
'End If
Case 3
MessageBox.Show("Error happened in data error case 3" _
& e.Context.ToString())
Case 4
e.ThrowException = False
'MessageBox.Show("Error happened in data error case 4" _
'& e.Context.ToString())
Case Else
MessageBox.Show("Error happened in data error case else" _
& e.Context.ToString())
End Select
End Sub
--------------------------------
Private Sub SwipeAccumulativeHoursBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SwipeAccumulativeHoursBindingNavigatorSaveItem.Click
Me.Validate()
Me.Save()
Me.SwipeAccumulativeHoursBindingSource.EndEdit()
If Me.Save() Then
MessageBox.Show("Your changes has been saved")
End If
End Sub
--------------------------
'
'save
'
Private Function Save()
Dim Saved As Boolean
If Me._keyscan_payrollDataSet.HasChanges Then
Try
Dim HoursAdd() As DataRow = Me._keyscan_payrollDataSet.SwipeAccumulativeHours.Select("", "", DataViewRowState.Added)
For x As Integer = 0 To HoursAdd.GetUpperBound(0)
With HoursAdd(x)
.Item("EmpNum") = cboEmployee.Text
.Item("InputType") = 4
.Item("Userid") = Environment.UserName
.Item("Timestamp") = Now
End With
Next x
Me.SwipeAccumulativeHoursTableAdapter.Update(HoursAdd)
Saved = True
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
Return Saved
End Function
'
------------------------------
I also had wanted to add the amount when the user enters it into the datagrid into a array for printing
'
'total paycode
'
Private Sub TotalPaycodes()
Dim dr As DataRow
Dim dt As DataTable
dt = _keyscan_payrollDataSet.SwipeAccumulativeHours
'load the paycodes into the table
For Each dr In dt.Rows
If Trim(dr.Item("PayCode").ToString) <> "Comment" Then
Dim paycodefound As Boolean = False
For y As Integer = 0 To arrayGroupPaycodes.GetUpperBound(0)
If dr.Item("PayCode").ToString <> "Comment" Then
If arrayGroupPaycodes

.GroupPaycode = dr.Item("PayCode").ToString Then
paycodefound = True
End If
If arrayGroupPaycodes

.GroupPaycode = "" And paycodefound = False Then
arrayGroupPaycodes

.GroupPaycode = dr.Item("PayCode").ToString
Exit For
End If
End If
Next y
End If
Next
' add the amounts into the table
For Each dr In dt.Rows
For y As Integer = 0 To arrayGroupPaycodes.GetUpperBound(0)
If Trim(dr.Item("PayCode")) <> "Comment" Then
If arrayGroupPaycodes

.GroupPaycode = CStr(dr.Item("PayCode")) Then
If CDec(dr.Item("Amount")) <> 0 Then
arrayGroupPaycodes

.TotalPaycode += CDec(dr.Item("Amount"))
End If
End If
End If
Next y
Next
'If Me._keyscan_payrollDataSet.HasChanges Then
' Try
' Dim CalcHours() As DataRow = Me._keyscan_payrollDataSet.SwipeAccumulativeHours.Select("", "", DataViewRowState.Added)
' For x As Integer = 0 To CalcHours.GetUpperBound(0)
' Dim paycodefound As Boolean = False
' For y As Integer = 0 To arrayGroupPaycodes.GetUpperBound(0)
' If arrayGroupPaycodes

.GroupPaycode = CalcHours(x).Item("PayCode").ToString Then
' paycodefound = True
' End If
' If arrayGroupPaycodes

.GroupPaycode = "" And paycodefound = False Then
' arrayGroupPaycodes

.GroupPaycode = CalcHours(x).Item("PayCode").ToString
' Exit For
' End If
' Next y
' Next x
' For x As Integer = 0 To CalcHours.GetUpperBound(0)
' For y As Integer = 0 To arrayGroupPaycodes.GetUpperBound(0)
' If arrayGroupPaycodes

.GroupPaycode = CStr(CalcHours(x).Item("PayCode")) Then
' If CDec(CalcHours(x).Item("Amount")) <> 0 Then
' arrayGroupPaycodes

.TotalPaycode += CDec(CalcHours(x).Item("Amount"))
' End If
' End If
' Next y
' Next x
' Catch ex As Exception
' MessageBox.Show(ex.ToString)
' End Try
'End If
End Sub
'
Thanks for the help
Kim