如何在datagridview中解决此错误 [英] how to solve this error in datagridview
问题描述
朋友们。我的Windows应用程序中有2个表单。当我点击第一个表单按钮时,我转到第二个表单。在第二种形式我有一个datagridview,它填充数据库中的值。这个datagridview显示了我想要的所有数据(行),以及在最后一行之后它是空的一行。这会为我的文本创建一个错误 - >对象引用未设置为对象的实例。在我的代码中,我使用了这样的foreach语句。
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// 某些代码在单元格上做一些工作
}
如何解决这个问题。
并删除最后一个空行
谢谢。
你应该设置<$ c您的 DataGridView
对象的$ c> AllowUserToAddRows 属性为false,并且不会显示添加行。
< blockquote>您的解决方案的问题仅在您的问题中....
您应该检查数据并在绑定到网格之前从最后删除空白行。
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.
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.
You should setAllowUserToAddRows
property of yourDataGridView
object to false, and the add row will not be shown.
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.
这篇关于如何在datagridview中解决此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!