0

So, I have the ms_trans DataGridView...

I'm trying to solve saving problem by this:

  • The for loop doesn't give back the last value

So, when I click save, the button insert a "" string to all cells, but every time I click this will added.

int Last = ms_trans.Rows.Count;    
if (ms_trans.Rows[Last - 1].Cells[0].Value.ToString() == "<append>")

This If statement has NullReferenceException. Why?

First, I added with Last-1, it worked (Only the Last gave OutOfRangeExeption). Why isn't working is this with getting the value?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Karlinna
  • 13
  • 2
  • Have you checked if `Last` is ALWAYS `> 0`? – Alexandre Severino May 05 '15 at 22:21
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders May 05 '15 at 23:05

0 Answers0