Hi, I'm using Visual Studio 2010 C#. I have a DataGridView on one of my Forms that is connected to SQL database table. That part works. I'm also using the dataGridView1_RowEnter
Event to populate the selected information into different Textboxes as I scroll down the grid. That works until I get past the last row.
As soon as I go beyond the length of the table (past the last row) and enter the first NULL row, I get the following error.
>> System.NullReferenceException was unhandled
Why is the "if (e.RowIndex >= 0)
" logic statement not preventing the error and how do I solve this problem?
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
if (e.RowIndex >= 0)
textBox1.Text = row.Cells.Value.ToString();
textBox2.Text = row.Cells.Value.ToString();
textBox3.Text = row.Cells.Value.ToString();
textBox4.Text = row.Cells.Value.ToString();