Maybe I'm approaching this the wrong way, but what I'm trying to do is to do is to validate a click event on a grid control. In testing the application the code below works fine, when, in fact, you click on a row on the grid, which contains data. That said, when I'm testing for errors and click on "blank" space, I get the following error: Null Reference Exception was unhandled. I've tried using both the IsDbNull and IsNothing functions, but they don't seem to work even though when I check the value returned it shows as Nothing. So the question is 1. Am I using the wrong function to get the value from a cell in the row and 2. How do I add code to make sure if the user clicks in the blank space (not on a row), I can catch the error?
Thanks,
Tom
Private Sub grdCharges_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdCharges.Click
If Me.grdCharges.SelectedRows.Count > 0 Then
If Not IsNothing(grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value) Then if Not IsDBNull(grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value) Then
ChargeID = grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value
End If
End If
End If
End Sub
Thanks,
Tom
Private Sub grdCharges_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdCharges.Click
If Me.grdCharges.SelectedRows.Count > 0 Then
If Not IsNothing(grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value) Then if Not IsDBNull(grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value) Then
ChargeID = grdCharges.Rows(grdCharges.CurrentRow.Index).Cells(0).Value
End If
End If
End If
End Sub