Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cell validating error icon

Status
Not open for further replies.

kimprogrammer

Programmer
Sep 15, 2008
160
CA
Hello
I have a datagrid wit cellvalidating. When I enter an incorrect value the small red error icon show on the left of the grid. But when I correct the value and tab to the next cell the icon remains. How do I get reid of it?



Thanks for the help
Kim
 
Does it persist when you change rows? commit the change? refresh the grid?

--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"

"Don't stop him. He's roll'n."
--------------------------------------------------
 
When I tab off the last field the error icon disappears. But so does my whole line. I'm trying to understand how all this cellvalidating and dataerror works together. So because I don't have this working properly maybe this is not the time to ask about this icon.

Thanks for the help
Kim
 
Kim-

I found this FAQ in my hunt to learn more about the DataGridView. It's pretty in depth but the examples are in C# (You can translate them pretty). There's an entire section on the error icons/etc.

faq796-6492

--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"

"Don't stop him. He's roll'n."
--------------------------------------------------
 
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(y).GroupPaycode = dr.Item("PayCode").ToString Then
paycodefound = True
End If
If arrayGroupPaycodes(y).GroupPaycode = "" And paycodefound = False Then
arrayGroupPaycodes(y).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(y).GroupPaycode = CStr(dr.Item("PayCode")) Then
If CDec(dr.Item("Amount")) <> 0 Then
arrayGroupPaycodes(y).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(y).GroupPaycode = CalcHours(x).Item("PayCode").ToString Then
' paycodefound = True
' End If
' If arrayGroupPaycodes(y).GroupPaycode = "" And paycodefound = False Then
' arrayGroupPaycodes(y).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(y).GroupPaycode = CStr(CalcHours(x).Item("PayCode")) Then
' If CDec(CalcHours(x).Item("Amount")) <> 0 Then
' arrayGroupPaycodes(y).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
 
Could .DefaultValuesNeeded be part of my solution? Does this only work if I have the columns being displayed on the datagrid?

Thanks for the help
Kim
 
My contract has ended so I won't get the opportunity to get this piece of the project completed - so no need to reply

Thanks for all the help!!!!!!!!!!!!!!!!!!!!


Thanks for the help
Kim
 
Thanks for this - but my problem was with the dataerror method because I did not want to include the whole dataset in the datagrid. I do have validation working with the cellvalidation method.

Thanks for the help
Kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top