Hi,
I have a MyDataGridView.DataSource = MyDataSet.Table(0) and the AllowUserToAddRows = True
Once the user have finished typing in the column zero I have to check if they didn't type invalid stuff. It have to be numeric and 4 chars long.
the code is:
And it is not all the time, but depending on how quick and stupid (i'm expecting stupid users, as usual) I click on the previous row or the AddNewRow row I get a the damn System.NullReferenceException on my If line:
I'm really not in the mood of just put a Try Catch, as it looks like bad programming in this case. I've already tried a couple variations with "is nothing" but no success
So my question:
Why is this happening?
How could test it won't cause a Null expection before testing the row value?
I have a MyDataGridView.DataSource = MyDataSet.Table(0) and the AllowUserToAddRows = True
Once the user have finished typing in the column zero I have to check if they didn't type invalid stuff. It have to be numeric and 4 chars long.
the code is:
VB.NET:
Private Sub Result_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Result.CellEndEdit
If e.ColumnIndex = 0 Then
If Not (IsNumeric(Result.Rows(e.RowIndex).Cells(0).Value) And Result.Rows(e.RowIndex).Cells(0).Value.ToString.Length = 4) Then
Result.Rows(e.RowIndex).Cells(0).Value = ""
MessageBox.Show("User ID must be a number with 4 digits", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
Me.LockBtn.ImageIndex = 2
CleanUp.Enabled = False
End Sub
And it is not all the time, but depending on how quick and stupid (i'm expecting stupid users, as usual) I click on the previous row or the AddNewRow row I get a the damn System.NullReferenceException on my If line:
VB.NET:
If Not (IsNumeric(Result.Rows(e.RowIndex).Cells(0).Value) And Result.Rows(e.RowIndex).Cells(0).Value.ToString.Length = 4) Then
I'm really not in the mood of just put a Try Catch, as it looks like bad programming in this case. I've already tried a couple variations with "is nothing" but no success
So my question:
Why is this happening?
How could test it won't cause a Null expection before testing the row value?
Last edited: