Null Reference Exception when int parsing DataGridView row values

Of course the programming languge isnt wrong. Its reporting to you that you are tring to use an object reference which is in fact null.

In the section dgvSelected.Rows[i].Cells[3].Value.ToString() one of the following is null

  • dgvSelected
  • dgvSelected.Rows
  • dgvSelected.Rows[i]
  • dgvSelected.Rows[i].Cells
  • dgvSelected.Rows[i].Cells[3]
  • dgvSelected.Rows[i].Cells[3].Value

As you can see, you should be doing alot of checking to make sure none of these objets is null

Edit: Strikeout some of those, as rightfully pointed out in comments the loop would not be entered if those were null.

Leave a Comment