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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Infinite Loop on Data Grid Cell Edit

Status
Not open for further replies.

GryphonsClaw

Programmer
Oct 3, 2005
9
0
0
US
I am having an issue with a data grid. When the cursor is in cell edit mode and the user clicks outside the grid say to another textbox or button, the data grid enters and infinite loop. I have a RowValidating procedure that is called, and completes with an e.Cancel = true. This is to catch any bad data, of course clicking outside of the grid, I don't want to commit the data.

Funny thing, if the cell is committed it works fine, if the cursor doesn't leave the grid it also works fine.

This is .NET 2.0
 
It might help if you post the code in your validation function.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top