Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends. i have 2 form in my windows application program. when i click on first form button i go to the second form. in second form i have a datagridview that it fill with values from database. this datagridview show all data(rows) that i want and one row more that it is empty after last row. and this create an error for me with this text-->"object reference not set to an instance of an object". in my code i used foreach statement like this.
C#
foreach (DataGridViewRow row in dataGridView1.Rows)
{
//some codes for doing some jobs on cells
}


how can i solve this problem.
and delete last empty row

thank you.
Posted
Updated 5-Aug-14 21:37pm
v2
Comments
Prashant. B. Chavan 6-Aug-14 3:23am    
"Object reference not set to an instance of an object" is very generic error. It means object that you are trying to use is not yet initialized. Need to more details on this.
_Starbug_ 6-Aug-14 3:30am    
i know this error is because of above code. if i solve datagridview problem. ican solve automatically

You should set AllowUserToAddRows property of your DataGridView object to false, and the add row will not be shown.
 
Share this answer
 
Comments
Animesh Datta 6-Aug-14 3:54am    
my 5+
Raul Iloc 6-Aug-14 3:57am    
Thank you Animesh for your vote!
Problem for your solution is in your question only....
You should review you data and remove the blank row from the last before binding to the grid.
 
Share this answer
 
Comments
_Starbug_ 6-Aug-14 3:59am    
i done it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900