Private Sub dgPW_RowValidating(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) _
Handles dgPW.RowValidating
Dim sErrorMsg = ""
With Me.dgPW
If Not IsNothing(.Rows(e.RowIndex)) Then
.EndEdit() 'trying this does not work, still errors
.Rows(e.RowIndex).Cells("UserName").ErrorText = Nothing
.Rows(e.RowIndex).Cells("Description").ErrorText = Nothing
.Rows(e.RowIndex).Cells("Password").ErrorText = Nothing
.Rows(e.RowIndex).Cells("Category").ErrorText = Nothing
End If
End With
'check to make sure fields are filled out that need to be filled out
With Me.dgPW
If .IsCurrentRowDirty = True Then
UpdatePending = True
If Len(.Rows(e.RowIndex).Cells("UserName").Value) = 0 Then
sErrorMsg = "User Name not supplied."
.Rows(e.RowIndex).Cells("UserName").ErrorText = "User Name is blank."
ElseIf Len(Me.dgPW.Rows(e.RowIndex).Cells("Password").Value) = 0 Then
sErrorMsg = "Password not supplied."
.Rows(e.RowIndex).Cells("Password").ErrorText = "Password is blank."
ElseIf Len(Me.dgPW.Rows(e.RowIndex).Cells("Description").Value) = 0 Then
sErrorMsg = "Description not supplied."
.Rows(e.RowIndex).Cells("Description").ErrorText = "Description is blank."
ElseIf Me.dgPW.Item("Category", e.RowIndex).Value Is Nothing Then 'convert the combo box, NULL means yes as well
sErrorMsg = "Category not supplied."
.Rows(e.RowIndex).Cells("Category").ErrorText = "Category is blank."
End If
If sErrorMsg.ToString.Length > 0 Then
MsgBox(sErrorMsg, MsgBoxStyle.OkOnly, "Error Updating Data")
e.Cancel = True
Else 'no error check for new password
If Strings.StrComp(sOldPW, .Rows(e.RowIndex).Cells("Password").Value.ToString) <> 0 Then
.Rows(e.RowIndex).Cells("UpdateDate").Value = FormatDateTime(Today, DateFormat.LongDate)
sOldPW = Nothing
End If
End If
Else
UpdatePending = False
End If
End With
End Sub