holemania
asked on
VB.NET Datagridview - Index out of range error
I have a datagridview that is working fine. However, I set a CellDoubleClick to do an event and everytime I accidently click on the header of a column, I get "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index".
I would I set it so that it would either exit the event or not give me an unhandled error? Below is my attempt to exit sub if they click on header, but that's where it error out with the index out of range.
I would I set it so that it would either exit the event or not give me an unhandled error? Below is my attempt to exit sub if they click on header, but that's where it error out with the index out of range.
If dgViewDetail.Rows(e.RowIndex).Cells("ID").Value = 0 Then
Exit Sub
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try it like this.
Private Sub dgViewDetail_CellDoubleClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgViewDetail.CellDoubleClick
If e.RowIndex < 0 Then Return
If dgViewDetail.Rows(e.RowIndex).Cells("ID").Value = 0 Then
Exit Sub
End If
End Sub
ASKER