When you bind a data source with the datagridview, the displayed table will automatically have multiple rows. Therefore, the rowcount attribute of the control or dtgridview. rows. the value of the count attribute is "number of rows in the data source table + 1", so it is easy to make an error when the data of the datagridview is recycled. For example:For (INT I = 0; I <dtgridview. rowcount; I ++) <br/>{< br/> for (Int J = 0; j <dtgridview. columncount; j ++) <br/>{< br/> string [] STRs = dtgridview [J, I]. value. tostring (); <br/> // Since rowcount is more than the actual number of rows, when I = RowCount-1, the value of this row is null, therefore, the error "object reference is not set to the instance of the object" is thrown. The correct way is to change the condition of the outermost loop to: I <dtgridview. RowCount-1 <br/>}< br/>}
It is easy to ignore this problem. You need to take a long time to learn about it ~