"System.NullReferenceException was unhandled" error after last valid row.
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.
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?
Hi Fernando, I had it that way and retried your suggestion just to make sure, but that still fails.
Mr_Fulano
ASKER
Hi Andy, yes...your suggestion works. The last row is negative and keeps increasing each time I enter it (i.e. -1. -2. -3...etc).
Is there a way to not show that last row at all?
Fernando Soto
Hi Andy, I was thinking that if this was happening when he passed the last row it had a -1 as the index and therefore would be an out of bounds index or no row. Was not near a computer to test and wanted him to have something to test for the moment.
Hi Fernando, I could understand why you suggested that for some of the other possible events but was puzzled why for the RowEnter event. Thanks for clarifying.
What is the value of e.RowIndex when it fails. You are apparently assuming it is less than zero.