title: c# getting specified cell (3rd column of last row) edited
body: <p>I have posted a topic about this earlier, but since I have made some mistakes so I decided to post a new topic to make sure that my question is clear enough.</p>
  
  <p>Here's my code :</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      if (dataGridView1.Rows.Count &gt; 0)
      {   
          int nRowIndex = dataGridView1.Rows.Count-1;
          if (dataGridView1.Rows[nRowIndex].Cells[2].Value != null)
          {
              textBox2.Text = dataGridView1.Rows[nRowIndex].Cells[2].Value.ToString();
          }
          else
          {
              MessageBox.Show("NULL");
          }
      }
  }
  </code></pre>
  
  <p>In my DataGridView, I have 3 columns which are ID, Name, Price.
  I want to get the last cell of Price which is at the last row of the DataGridView.
  The above code causes me to have NullReferenceException and the specified cell does have data in it.
  Anyone know how to solve this problem?</p>